Community
    • Login

    Regex: How do I search for My_String [any characters] [quotation mark] ?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    18 Posts 4 Posters 3.7k 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.
    • IanSunlunI
      IanSunlun @PeterJones
      last edited by IanSunlun

      @PeterJones To confirm, I just found out that the string I am searching for is sometimes spread over 2 lines.

      i.e. ThisIsTheStringIAmSearchingFor - this exact specific string - is normally on the same line. But sometimes its like this:
      ThisIsTheStringIAmSearch
      ingFor

      I dont know where the line break may occur, or even if a line break does occur. How do I make sure I find that string in the Find: box?

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @IanSunlun
        last edited by PeterJones

        @IanSunlun ,

        You mean, we can no longer assume that My_String prefix will be all together? That makes it harder.

        If we could assume My_String prefix was always on the same line, then My_String((?s).*?)" would match, and everything (including the newline) would be in ${1} for the replacement.

        However, if we can no longer assume that, we will have to have one capture group per letter, with an optional newline between every single character

        • FIND = (T)\R?(h)\R?(i)\R?(s)\R?(I)\R?(s)\R?(T)\R?(h)\R?(e)\R?(S)\R?(t)\R?(r)\R?(i)\R?(n)\R?(g)\R?(I)\R?(A)\R?(m)\R?(S)\R?(e)\R?(a)\R?(r)\R?(c)\R?(h)\R?(i)\R?(n)\R?(g)\R?(F)\R?(o)\R?(r)\R?"
        • REPLACE = ${1}${2}${3}...${29}${30}.mhtml"
          (I did not show all thirty ${N}… I hope you can figure out what goes in the …)

        I think @Alan-Kilborn has a script he published a few months back that does a “space insensitive” search, but i am having trouble finding it. I hope he can post a link to it, because I think that might work better for you.

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

          @PeterJones said in Regex: How do I search for My_String [any characters] [quotation mark] ?:

          I think @Alan-Kilborn has a script he published a few months back that does a “space insensitive” search

          HERE is the requested script (only 3 weeks old, not months).

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

            @Alan-Kilborn and @PeterJones
            thanks, I installed that and it appears its working for me.

            To add a little complication into the mix, I am searching in .mhtml files.
            These files have a habit of putting an ‘=’ (equals sign) sign at the end of many lines. Is there anything I can add to the search term to include the possibility of finding an equals sign in the midst of a search phrase ?

            So, I might get: MyStringabcdef=
            ghijklm12345

            Alan KilbornA 1 Reply Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @IanSunlun
              last edited by

              @IanSunlun

              Is there anything I can add to the search term to include the possibility of finding an equals sign in the midst of a search phrase ?

              I suppose you could change the script part where it uses r'\h*' to be r'[\h=]* instead…

              IanSunlunI 1 Reply Last reply Reply Quote 1
              • IanSunlunI
                IanSunlun @Alan Kilborn
                last edited by IanSunlun

                @Alan-Kilborn I’ll give that a try.
                What happens if I want to keep some of what I find in the search string in the replacement string?

                E.g. lets say I find:
                MyStringAbcd=
                efg12345xyz

                And I want to replace it with:
                MyNewStringAbcdefg99999xyz

                Is it possible to store in, for example, ${1} the Abcdefg ?

                Alan KilbornA Neil SchipperN 2 Replies Last reply Reply Quote 0
                • Alan KilbornA
                  Alan Kilborn @IanSunlun
                  last edited by Alan Kilborn

                  @IanSunlun said in Regex: How do I search for My_String [any characters] [quotation mark] ?:

                  What happens if I want to keep some of what I find in the search string in the replacement string?

                  I guess that could get tricky.
                  I don’t have all the answers. :-(
                  I suppose it is something you have to experiment with, see if you can make it do what you want it to.

                  1 Reply Last reply Reply Quote 1
                  • Neil SchipperN
                    Neil Schipper @IanSunlun
                    last edited by

                    @IanSunlun If you’re confident a trailing equal sign =\R won’t ever appear in a context where you want to preserve it, then do a pass where you just blow them all away (before the pass where you do other text replacement).

                    IanSunlunI 1 Reply Last reply Reply Quote 1
                    • IanSunlunI
                      IanSunlun @Neil Schipper
                      last edited by

                      @Neil-Schipper thanks, yes, I just did that a few mins ago.
                      I was concerned that .mhtml file was limiting line length to 76 chars for a reason.
                      I blew the =\r\n away for all the files, and they load up in the browser OK, so hopefully the = was not critical.

                      PeterJonesP 1 Reply Last reply Reply Quote 0
                      • PeterJonesP
                        PeterJones @IanSunlun
                        last edited by PeterJones

                        @IanSunlun ,

                        Wait, 72 character line length and = ending a line. I think your .mhtml might be using Quoted Printable. The = at the end of a line does have a meaning in QP.

                        You really need to learn the file types you are editing before you start hacking around at things willy-nilly. Good luck getting that .mhtml to work right after all your edits.

                        IanSunlunI 1 Reply Last reply Reply Quote 1
                        • IanSunlunI
                          IanSunlun @PeterJones
                          last edited by IanSunlun

                          @PeterJones
                          I’m trying to download my website for offline viewing. I downloaded .mhtml files. There seemed to be no other option for .mhtml saving - the default seems to have been this Quoted Printable format you mentioned.

                          I took out all the =\r\n episodes in all the .mhtml files and loaded them back into my browser.
                          Nothing seems to have changed. Its browsing and viewing them all fine. Now my other search and replace tasks will be easier.
                          All I am needing is offline browsing.

                          PeterJonesP 1 Reply Last reply Reply Quote 0
                          • PeterJonesP
                            PeterJones @IanSunlun
                            last edited by

                            @IanSunlun ,

                            I just checked; yes, saving a webpage as .mhtml from a major browser will use quoted-printable.

                            If you really want to correctly do this:
                            b51566b2-3818-44da-ae91-9e391acbcc46-image.png

                            1. Select one part (the HTML part of the multipart, for example)
                              7ba2d2b6-b23b-4324-9aa4-9dffc06a5b90-image.png
                            2. Plugins > MIME Tools > Quoted Printable Decode
                              38b62dc5-c946-4a92-a1d1-2a8f1a709ea0-image.png
                            3. Do your search/replace
                            4. Select all that text again
                            5. Plugins > MIME Tools > Quoted Printable Encode

                            You will find it’s much easier to work with that way.

                            IanSunlunI 1 Reply Last reply Reply Quote 1
                            • IanSunlunI
                              IanSunlun @PeterJones
                              last edited by

                              @PeterJones Ah, thats good to know, thanks !

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