#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2017
    Posts
    1
    Rep Power
    0

    replace alphanumeric characters behind search pattern


    Hi all
    I have to replace some text in a MT942 file

    File content as example:
    :20:1234567
    :21:9876543210
    :25:10020030/1234567
    :28C:5/1
    :34F:EURD20,50
    :34F:EURC155,34
    :13D:C1311130945+0000
    :61:1311131113CR155,34NTRFNONREF//55555
    :86:166?00SEPA-UEBERWEISUNG?109315 ?20EREF+987654123456?21SVWZ+Rechnung-Nr. 123455056?22734 und 123455056735 ?30COLSDE33XXX?31DE91370501980100558000 ?32Max Mustermann
    :61:1311131113DR20,50NDDTNONREF//55555
    :86:105?00SEPA-BASIS-LASTSCHRIFT?109316 ?20EREF+987654123497?21MREF+10023?22CRED+DE54ZZZ09999999999?23SVWZ+Versicherungsbeitrag 2 ?24013?30WELADED1MST?31DE87240501501234567890?32XYZ Versicherungs AG?34?991blabla?60ofuguafjsbfb?61jbfz9zvdzevfvzf
    :90D:1EUR20,50
    :90C:1EUR155,34

    Now i should replace everything with no content between:
    ?34?991blabla?60
    search for ?34
    replace with nothing until ?60

    I have try a lot but not succeeded.
    sed -E '/\?34/s/\?34(.*[?])/\?34?/g

    This replace all until ?61. Don't understand why not until ?60.
    Please help a newbie.
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2010
    You regex example does not contain any search for ?60.

    You will need to use the positive lookbehind, to tell the match must start with ?30 without including it.
    For validate ?60, you will need to use the positive lookahead.

    Try have a look at this regex:
    (?<=\?34).*(?=\?60)

    The non-greedy version:
    (?<=\?34).*?(?=\?60)

IMN logo majestic logo threadwatch logo seochat tools logo