• Login
Community
  • Login

I need a quick and dirty regular expression.

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 2 Posters 5.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.
  • Q
    qucikuuuu
    last edited by Jul 12, 2015, 10:54 PM

    This should be simple, but I’m messing it up somehow. All I want to do is search a large body of text and use a regular expression to replace all occurrences of “pen” or “crayon” with “pencil”, but I’m somehow failing to do this with what Notepad++ skills I have, can anyone help?

    For example, “I ate my pen and my crayons today” should become “I ate my pencil and my pencils today”.

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Jul 13, 2015, 12:59 AM Jul 13, 2015, 12:55 AM

      Hello quickuuuu,

      No problem ! We’ll use the vertical bar character to search for the alternative patterns pen, and crayon, simultaneously.

      So :

      • Open the Replace dialog

      • Check the Regular expression search mode

      • Check the options Match case and Wrap around, if necessary

      • Type pen|crayon in the Fin what zone

      • Type pencil in the Replace with zone

      • If you previously select the block of text to operate, check also the In selection option

      • Finally, click on the Replace All button

      Et voilà !

      Best Regards

      guy038

      P.S. :

      You’ll find good 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

      1 Reply Last reply Reply Quote 1
      • Q
        qucikuuuu
        last edited by Jul 13, 2015, 1:07 AM

        Odd, I’ve tried exactly that to no success, is there anyway to debug my install? That could be an issue, I could even be out of date, is there anyway to check my version number?

        The only other thing that might be interfering is that my locale is Japanese, would that cause issues?

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by guy038 Jul 13, 2015, 1:29 AM Jul 13, 2015, 1:28 AM

          Hi quickuuuu,

          Just hit on the F1 key to get your present N++ version. Anyway, in order to use the PCRE, your version should be >= v6.0


          Secondly, you must NOT click twice on the Replace All button or you would replace, wrongly, the first part of the word pencil

          Therefore, a better syntax would be :

          SEARCH : \b(pen|crayon)(s)?\b

          REPLACE : pencil(?2s)

          Notes :

          • The \b form is an assertion which stands for the limit between a non-word character and a word character, or the opposite

          • The form (s)? is the final optional character s, located in group 2

          • In replacement, the syntax (?2s) means that we must rewrite the final s, if search group 2 exists

          Cheers

          guy038

          1 Reply Last reply Reply Quote 2
          • Q
            qucikuuuu
            last edited by Jul 13, 2015, 2:11 AM

            Wow… I’m all the way back on 5.9.6.2, I’ll come back tommorow when I’ve got the new one. Are there any auto-update facilities?

            1 Reply Last reply Reply Quote 0
            • Q
              qucikuuuu
              last edited by Jul 13, 2015, 12:49 PM

              Thanks, that’s done it!

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