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

    Join Date
    Sep 2017
    Rep Power

    replace alphanumeric characters behind search pattern

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

    File content as example:
    :86:166?00SEPA-UEBERWEISUNG?109315 ?20EREF+987654123456?21SVWZ+Rechnung-Nr. 123455056?22734 und 123455056735 ?30COLSDE33XXX?31DE91370501980100558000 ?32Max Mustermann
    :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

    Now i should replace everything with no content between:
    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
    Rep Power
    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:

    The non-greedy version:

IMN logo majestic logo threadwatch logo seochat tools logo