Regex: How do I search for My_String [any characters] [quotation mark] ?
-
@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
ingForI 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?
-
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, thenMy_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.
- FIND =
-
@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).
-
@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 -
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 ber'[\h=]*
instead… -
@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=
efg12345xyzAnd I want to replace it with:
MyNewStringAbcdefg99999xyzIs it possible to store in, for example, ${1} the Abcdefg ?
-
@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. -
@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). -
@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. -
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.
-
@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. -
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:
- Select one part (the HTML part of the multipart, for example)
- Plugins > MIME Tools > Quoted Printable Decode
- Do your search/replace
- Select all that text again
- Plugins > MIME Tools > Quoted Printable Encode
You will find it’s much easier to work with that way.
- Select one part (the HTML part of the multipart, for example)
-
@PeterJones Ah, thats good to know, thanks !