Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

null character handling in search/replace

2. Help
Ken Madsen
2013-09-25
2013-09-25
  • Ken Madsen
    Ken Madsen
    2013-09-25

    I have null delimited files and I needed to replace occurrences of consecutive null characters with ones with a space between. The first thing I noticed is while an extended search for \0 would land on null characters, \0\0 would not find consecutive ones. I tried an alternate approach where I replaced \0 with commas, then replaced consecutive commas with commas with one space char in between, but when I attempted to replace , with \0, it just removed the commas, rather than putting in null characters.

    These appears to be bugs, but I thought I'd ask and perhaps see if there are workarounds.

    Using 6.4.5

     
  • THEVENOT Guy
    THEVENOT Guy
    2013-09-25

    Hello Ken,

    The current version of the PCRE ( Perl Regular Regular Expressions ) engine, included in N++ doesn't handle properly the NULL characters.

    In fact, François-R Boyer, a major N++ developer, improved the PCRE engine of N++, resolved some bugs, relative to the lookbehind feature and included a good management of null characters. Just follow this link below, to get his last version, on the beginning of June :

    http://sourceforge.net/projects/npppythonplugsq/files/Beta%20N%2B%2B%20regex%20code/

    • Download the file readme.txt : it's a very small file, easy to read, which explains the different improvements.

    • Stops any instance of Notepad++, if any

    • In your N++ main folder, rename the file SciLexer.dll, let say, with the name SciLexer.old, for example.

    • Download the new file SciLexer.dll, in your main N++ folder : its a modified version of the original SciLexer.dll, version 2.2.7. Just note that, in this modified DLL, the version number has NOT been updated and is still 2.2.7.

    • Restart Notepad++

    Just a rapid example :

    In a new tab, type in 30 dashes. Then, in regular expression mode :

    SEARCH : -
    REPLACE : \x00

    Click on the Replace All button => you obtain 30 NULL characters. Nice :)

    Now, perform, for example, the second Search/Replacement below :

    SEARCH : \x00{5}
    REPLACE : $0

    with a space, AFTER $0

    Click, again on the Replace All button => you obtain a string of NULL characters, separated, each five positions with a SPACE, so there's a space at the end of the replaced string :-)

    ( BTW, remember that the form $0 or $&, in the replacement part, means : all the search string )


    IMPORTANT :

    • For some reasons that I don't know, this modified and efficient version of the PCRE engine, by François-R Boyer, has NEVER been part of an official version yet ! It's really a pity :(

    Moreover, don't forget that this modified version is based on Scintilla 2.2.7 and the new 6.5 version of N++ is now based on Scintilla 3.3.4.

    Thus, you may keep the TWO versions ( François-R Boyer's 2.2.7 version and Scintilla's 3.3.4 version ) in N++ directory, doing the right renaming when necessary. But, if François don't update his improved version, it would be preferable to keep TWO folders :

    • One, with N++ version 6.4.5, LAST version based on Scintilla 2.2.7, for better S/R in regex mode.

    • An other, with current version of N++, based on Scintilla 3.3.4 or above, but without François's PCRE improvements, for usual purposes.

    Best regards,

    guy038

     
    Last edit: THEVENOT Guy 2013-09-25