• Login
Community
  • Login

What's Regex syntax of "Replace with"?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 2 Posters 3.0k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 古
    古旮
    last edited by Dec 2, 2016, 4:19 PM

    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!

    1 Reply Last reply Reply Quote 0
    • 古
      古旮
      last edited by Dec 2, 2016, 4:41 PM

      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!

      1 Reply Last reply Reply Quote 0
      • G
        guy038
        last edited by guy038 Dec 2, 2016, 8:48 PM Dec 2, 2016, 8:46 PM

        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 its 6.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://www.rexegg.com

        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

        1 Reply Last reply Reply Quote 0
        • 古
          古旮
          last edited by Dec 3, 2016, 11:10 AM

          Thank you very much!

          1 Reply Last reply Reply Quote 0
          2 out of 4
          • First post
            2/4
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors