Bug in regexp replace?

oget
2013-04-01
2013-04-03
  • oget
    oget
    2013-04-01

    original:

    00000327  3C1B              cmp al,0x1b
    00000329  75F4              jnz 0x31f
    0000032B  F9                stc
    0000032C  C3                ret
    0000032D  0E                push cs
    

    replace "^[^ ]+ [^ ]+ +" on ""

    result:

    cmp al,0x1b
    jnz 0x31f
    push cs
    

    // Sublime Text and Pspad work properly.

     
  • I'm not certain what should be the "standard"/"correct" behavior in this case. Note that Pspad regex is line based (i.e. will not find "b[^ ]" in the above text as each line is scanned independently), and thus might not give the same result. Sublime Text will give the same result as N++ if you click on the "Replace" button several times instead of clicking on the "Replace All" button. N++ has a consistent behavior if you click on "Replace All" or if you click several times on "Replace".

    If you want to be certain next match goes to next line, and does not match the instruction which is moved at the start of line after the replace, you could replace "^[^ ]+ +[^ ]+ +(.*)" by "\1" without . matches newline.

     
  • THEVENOT Guy
    THEVENOT Guy
    2013-04-03

    Hi oget,

    The answer of François-R Boyer is quite correct, but we can even do more simple !

    In your original dessassembling text, it's seem that :

    • TWO spaces always seperate line numbers from hexadecimal codes
    • Only ONE space separates the instruction name from it(s) parameter(s)

    So, if we search anything from beginning of line and ending with
    THREE spaces, we get all the characters before the instruction name,
    of each line, to be deleted

    Thus, whatever the position of cursor is, in the file, either with the
    Replace button or with the Replace All button :

    Search          :     ^.+ {3}      ( ONE space AFTER the sign PLUS )
    Replacement :     EMPTY string

    can obtain the same result !

    We can also write it :

    Search          :     ^.+     ( THREE spaces AFTER the sign PLUS )
    Replacement :     EMPTY string

    Note : The option '. matches newline' MUST be OFF !!

    Cheers,

    guy038

     
    Last edit: THEVENOT Guy 2013-04-03