What's Regex syntax of "Replace with"?
-
I want to add brackects.
first attempt:
Find what:s
Replace with:(s)It makes no differrence.
second attempt:
Find what:s
Replace with:(s)Succeeded.
So I find that, “(” and “)” need to be “(” and “)” in the “Replace with”. But I can’t find it documented anywhere.
In the wiki page of notepad++ (http://docs.notepad-plus-plus.org/index.php/Regular_Expressions), under “Substitutions” paragraph, where we can see “\a,\e,\f,\n,\r,\t,\v…” and “$&, $MATCH, ${^MATCH}”, there is no telling that “(” needs to be “(”.
Another place, (http://www.boost.org/doc/libs/1_61_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html), there is not even anything about the “replace with”, can’t even find “$MATCH”. There is only syntax of “find what”.So my question is, where to find the document about the “replace with”? Apparently, the one in the first link above is not complete.
And, are there any characters other than “(” and “)” need to follow a “” to represent themselves?
Thank you! -
Sorry that I didn’t look at the preview. There are some “\” missing. Now I post it again:
I want to add brackects.
first attempt:
Find what:s
Replace with:(s)It makes no differrence.
second attempt:
Find what:s
Replace with:\(s\)Succeeded.
So I find that, “(” and “)” need to be “\(” and “\)” in the “Replace with”. But I can’t find it documented anywhere.
In the wiki page of notepad++ (http://docs.notepad-plus-plus.org/index.php/Regular_Expressions), under “Substitutions” paragraph, where we can see “\a,\e,\f,\n,\r,\t,\v…” and “$&, $MATCH, ${^MATCH}”, there is no telling that “(” needs to be “\(”.
Another place, (http://www.boost.org/doc/libs/1_61_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html), there is not even anything about the “replace with”, can’t even find “$MATCH”. There is only syntax of “find what”.So my question is, where to find the document about the “replace with”? Apparently, the one in the first link above is not complete.
And, are there any characters other than “(” and “)” need to follow a “\” to represent themselves?
Thank you! -
Hello, 古旮,
You’ll find the official documentation, about the new Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v1.48.0 ), used by
Notepad++
, since its6.0
version, at the TWO addresses below :http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
-
The FIRST link explains the syntax, of regular expressions, in the SEARCH part
-
The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part
We may, also, look for valuable informations, on these sites, below :
http://www.regular-expressions.info
http://perldoc.perl.org/perlre.html
To summarize :
-
The 14 characters, which have a special meaning, in regexes, when used in the search part, are :
. * + ? ( ) [ ] { } ^ $ | \
-
The 6 characters, which have a special meaning, in regexes, when used in the replacement part, are :
( ) \ $ ? :
If you need to use any of these meta-characters, as a simple literal character, just escape it with the usual
\
antislash character !Notes :
-
Most of a time, in search part, the closing square bracket (
]
) is just seen as a literal character -
Generally, in Replacement part, the 3 characters : dollar (
$
) , exclamation mark (?
) and colon (:
) are considered as literal symbols, too !
Best Regards,
guy038
-
-
Thank you very much!