Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    RegEx Search and replace setup

    General Discussion
    4
    10
    1371
    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.
    • R van Wingerden
      R van Wingerden last edited by

      I am editing wordpress.sql database file
      I remove the WP plugin “Who hit the page”, next
      I have to remove in all my pages (800+) the hit function.

      Syntac is [whohit] variable text length [/whohit] plus carriage return.

      I use the syntax in search [whohit] + [/whohit], but don’t work
      Can some one help me out?

      Thx Robert

      andrecool-68 1 Reply Last reply Reply Quote 0
      • andrecool-68
        andrecool-68 @R van Wingerden last edited by

        @R-van-Wingerden
        Find and replace
        Find : [whohit .*?/whohit]
        Replace:

        1 Reply Last reply Reply Quote 1
        • R van Wingerden
          R van Wingerden last edited by

          @andrecool-68 said:

          [whohit .*?/whohit]
          Thx for your replay
          It is working result is, 1.582.600 hits to many, many letters ar hit to…

          Thx Robert

          1 Reply Last reply Reply Quote 0
          • R van Wingerden
            R van Wingerden last edited by R van Wingerden

            When I search for only “[whohit” I get 747 hits
            When I search for only “/whohit]” I get 747 hits
            So the search syntax works
            Only the variable text length (incl, space is) not working

            PLS Advice

            Thx Robert

            1 Reply Last reply Reply Quote 0
            • R van Wingerden
              R van Wingerden last edited by R van Wingerden

              @R-van-Wingerden said:
              I found my solution by using backslash[whohit(.*)backslash/whohit]
              Problem solved
              Thx Robert

              1 Reply Last reply Reply Quote 1
              • PeterJones
                PeterJones last edited by

                @R-van-Wingerden said:

                I found my solution by using backslash

                Good job.

                Only the variable text length (incl, space is) not working
                PLS Advice

                The reason is because in regular expression mode, the square bracket pair [] defines a character set – so Notepad++ matches any single character found between the square brackets. When you had only [whohit or only /whohit], there was not a pair of brackets, so Notepad++ fell back to treating them as literal characters. By adding the backslash before the first [, you told Notepad++'s regex engine to treat it as a literal [, rather than the start of a pair; and since there was no start to the pair, Notepad++ treated the closing ] as a literal as well.

                This FAQ and the documentation it points to (especially the Boost regular expression docs) will help you more fully understand regular expressions in general and the Boost regular expression syntax (which is the flavor of regex used in Notepad++) in particular.

                Alan Kilborn 1 Reply Last reply Reply Quote 3
                • Alan Kilborn
                  Alan Kilborn @PeterJones last edited by

                  I would not normally reply just to say this, but: This has been a very hard thread to follow; my head hurts. But I have other things to add:

                  @andrecool-68 has a bad habit of helping out with searches of this sort without explicitly telling posters to set the Search mode to Regular expression. Okay, okay…in this case “regex” is in the posting title, but still, if you are going to provide a Find expression to someone, perhaps someone very noob, also indicate the Search mode right alongside the Find (and/or Replace) expressions.

                  @PeterJones said:

                  When you had only [whohit … there was not a pair of brackets, so Notepad++ fell back to treating them as literal characters.

                  My experience/testing in this area indicates that Notepad++ will say Find: Invalid regular expression and won’t “fall back” to anything else. This is for [.

                  For ] yes, it will be treated literally if there is no opening bracket coming before (as Peter has already correctly said).

                  R van said:

                  When I search for only “[whohit” I get 747 hits

                  Are you sure you are in regular expression Search mode when you got this? Hmmmm… or probably you aren’t paying attention to detail and giving us exactly what you searched for.

                  1 Reply Last reply Reply Quote 4
                  • PeterJones
                    PeterJones last edited by

                    @Alan-Kilborn said:

                    My experience/testing in this area indicates that Notepad++ will say Find: Invalid regular expression and won’t “fall back” to anything else. This is for [.

                    You’re right. I should have tried before I commented.

                    1 Reply Last reply Reply Quote 4
                    • Alan Kilborn
                      Alan Kilborn last edited by

                      if you are going to provide a Find expression to someone, perhaps someone very noob, also indicate the Search mode right alongside the Find (and/or Replace) expressions

                      Perhaps a template helps to not forget important details. The following can be copied and pasted into this forum and then filled-in / deleted-from:

                      Bring up the **Find** window (ctrl+f).
                      Bring up the **Replace** window (ctrl+h).
                      Bring up the **Find in Files** window (ctrl+shift+f).
                      Bring up the **Mark** window (*Search* menu > *Mark...*).
                      **Find what** box: ``
                      **Replace with** box: ``
                      **Replace with** box: ***make sure this box is empty!***
                      **Search mode**: Normal Extended Regular expression
                      **Backward direction**: unticked
                      **Match whole word only**: unticked
                      **Match case**: unticked
                      **Wrap around**: unticked
                      **. matches newline**: unticked
                      **In selection**: unticked
                      **Bookmark line**: unticked
                      **Purge for each search**: unticked
                      Press the **Find Next** button.
                      Press the **Count** button.
                      Press the **Find All in All Opened Documents** button.
                      Press the **Find All in Current Document** button.
                      Press the **Replace** **Replace All** **Replace All in All Opened Documents** button.
                      Press the **Replace All** button.
                      Press the **Replace All in All Opened Documents** button.
                      Press the **Find All** button.
                      Press the **Replace in Files** button.
                      Press the **Mark All** button.
                      Press the **Clear all marks** button.
                      

                      So the idea is to use the template when composing here (or better, in a scratch N++ tab) is: fill in the blanks, delete out entire lines if they don’t apply or don’t matter, and remove un from unticked if you need to specify ticked for an option.

                      Here’s an example of template usage that (might) be accurate for this thread:

                      Bring up the **Replace** window (ctrl+h).
                      **Find what** box: `[whohit .*?/whohit]`
                      **Replace with** box: ***make sure this box is empty!***
                      **Search mode**: Regular expression
                      **Wrap around**: ticked
                      **. matches newline**: unticked
                      Press the **Replace All** button.
                      

                      which produces when posted:

                      Bring up the Replace window (ctrl+h).
                      Find what box: [whohit .*?/whohit]
                      Replace with box: make sure this box is empty!
                      Search mode: Regular expression
                      Wrap around: ticked
                      . matches newline: unticked
                      Press the Replace All button.

                      [Of course, apologies to non-English users of Notepad++…]

                      This is a big FWIW !!

                      1 Reply Last reply Reply Quote 3
                      • Alan Kilborn
                        Alan Kilborn last edited by

                        Tweak to template due to editing error and not completely checking before posting (did I get it completely right this time? hmmmm):

                        Bring up the **Find** window (ctrl+f).
                        Bring up the **Replace** window (ctrl+h).
                        Bring up the **Find in Files** window (ctrl+shift+f).
                        Bring up the **Mark** window (*Search* menu > *Mark...*).
                        **Find what** box: ``
                        **Replace with** box: ``
                        **Replace with** box: ***make sure this box is empty!***
                        **Search mode**: Normal Extended Regular expression
                        **Backward direction**: unticked
                        **Match whole word only**: unticked
                        **Match case**: unticked
                        **Wrap around**: unticked
                        **. matches newline**: unticked
                        **In selection**: unticked
                        **Bookmark line**: unticked
                        **Purge for each search**: unticked
                        Press the **Find Next** button.
                        Press the **Count** button.
                        Press the **Find All in All Opened Documents** button.
                        Press the **Find All in Current Document** button.
                        Press the **Replace** button.
                        Press the **Replace All** button.
                        Press the **Replace All in All Opened Documents** button.
                        Press the **Find All** button.
                        Press the **Replace in Files** button.
                        Press the **Mark All** button.
                        Press the **Clear all marks** button.```
                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post
                        Copyright © 2014 NodeBB Forums | Contributors