Menu

Problem with a simple replace script

Help
2015-09-17
2015-09-18
  • Pyry Piirainen

    Pyry Piirainen - 2015-09-17

    Hello,

    I am experiencing a problem which is as follows:
    My text file has contents "(((" (three parantheses)
    I run a the command editor.replace("(", " ( ")
    So I expect the output to have the three parentheses with a padding of one space added on each side: " ( ( ( "
    However, I recieve an output of : " " (6 spaces) where the parentheses have disappeared. The same happens with ")", but I not with any other characters I've tried (including {, }, [, and ]).

    Is this a bug or am I doing something wrong?

    I am using Notepad++ 6.8.3 and Python Script 1.0.8.0

    Thanks!

     
  • Sasumner

    Sasumner - 2015-09-18

    This appears to be a bug. However, I noticed that the rereplace function performs this replacement correctly; if written as follows for your replacement: editor.rereplace(r"\(", r" \( ")

    Note that the parentheses are special regex characters, so they must be escaped with a backslash.

     

    Last edit: Sasumner 2015-09-18

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.