Find and replace with regular expressions
Find and replace with regular expressions
Hi all - I needed to remove a chunk of content from every topic which included an email jscript link so it was difficult to use the standard Find and replace option in Flare. I eventually via a blog link on Dave Lee's site (https://ukauthor.wordpress.com/) found this post describing how to search for the whole chuck through Notepad++ which I use constantly now with the Top Nav output.
http://eric.cressey.org/blog/2013/09/08/regex/
This saved me a lot of time and was easy to follow even tho I've not used regular expressions before. Hopefully it will do the same for someone else ...
Thanks to Dave as usual as well as Eric Cressey
http://eric.cressey.org/blog/2013/09/08/regex/
This saved me a lot of time and was easy to follow even tho I've not used regular expressions before. Hopefully it will do the same for someone else ...
Thanks to Dave as usual as well as Eric Cressey
Ann
Started on Flare 3, now on Flare 2017 r2 + Capture (occasionally) and Analyser (very occasionally)
Windows 10 Enterprise
Started on Flare 3, now on Flare 2017 r2 + Capture (occasionally) and Analyser (very occasionally)
Windows 10 Enterprise
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
I'm a fairly advanced regex user. One of my colleagues has encountered a situation where the H1 in every topic is enclosed in a table, with some of the tables containing two columns with an icon in the first column. He wants to remove the tables and end up with an image floated left, followed by the H1.
As far as I can tell, this requires regex that supports multi-line matching. Also as far as I can tell, Flare only supports single-line matching. We discussed doing it in multiple passes, starting with a pass to remove all the carriage returns. Neither of us was big on that idea.
Does anyone know of a tool that can do regex find and replace and supports multi-line regex matching? We have used FAR for some other stuff, and it works well (and can be quite dangerous ) but also doesn't seem to support multi-line matching.
Thanks for any thoughts.
Best,
Bob
As far as I can tell, this requires regex that supports multi-line matching. Also as far as I can tell, Flare only supports single-line matching. We discussed doing it in multiple passes, starting with a pass to remove all the carriage returns. Neither of us was big on that idea.
Does anyone know of a tool that can do regex find and replace and supports multi-line regex matching? We have used FAR for some other stuff, and it works well (and can be quite dangerous ) but also doesn't seem to support multi-line matching.
Thanks for any thoughts.
Best,
Bob
-
- Senior Propellus Maximus
- Posts: 2632
- Joined: Wed Apr 14, 2010 8:01 am
- Location: Surrey, UK
Re: Find and replace with regular expressions
Bob, I use FAR loads (in assorted scripts written by a former colleague so I'm no expert) and it DOES support multi-line stuff. There's an option Ignore CR LF chars.
Started as a newbie with Flare 6.1, now using Flare 2023.
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
Thanks so much! I missed that control... This may be our salvation!
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
I just looked for that control, and haven't found it in version 2.01. I found a Line Breaks submenu in the Tools menu. It seems to be more of a line break encoding selector. In the Content Pattern box, there is a Wrap Lines control, but that selects whether the Content Pattern box wraps or scrolls right when lines are longer.ChoccieMuffin wrote:Bob, I use FAR loads (in assorted scripts written by a former colleague so I'm no expert) and it DOES support multi-line stuff. There's an option Ignore CR LF chars.
I'm not a FAR expert, so I could easily have missed something.
Thanks for any thoughts!
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
Found it:
http://findandreplace.sourceforge.net/d ... 1-faq.html
There is an FAQ on multiline. It's a regex control, not a FAR UI control...
Best,
Bob
http://findandreplace.sourceforge.net/d ... 1-faq.html
There is an FAQ on multiline. It's a regex control, not a FAR UI control...
Best,
Bob
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
It's been quite a journey, but I think I've found it.
To do a multi-line regex in FAR, precede find code with (?s).
Interestingly, this works in Flare as well. Flare's find (in the text editor itself) has the added advantage of showing you what it's matched with the regex. (FAR just does it, which is a little disconcerting.) So you can do a Find-and-Replace on all files in Flare and see what each match is going to replace with Find Next.
Flare has one oddness in the replacement side.
Background - Regex can find and store stuff into groups, and you use the groups you want.
For example,
would find everything within an H1, followed by everything up to, but not including a <table> tag. The contents of the H1 would be stored in Group 1, and Group 2 would contain everything between the H1 and the table.
Most Regex implementations allow you to use a "$" to reference a group in a replacement string. So you might use the above like this:
That would put the contents of the original H1 into an H2, and follow it with whatever code followed.
Flare requires you to use a backslash to reference the group rather than a dollar sign:
would result in roughly the same thing as the code above.
I also couldn't find a way for Flare to insert a newline as part of the replacement string.
In case anyone's interested, my code for finding an image and an H1 contained within a table that immediately follows a <body. tag (which is what I'm trying to replace) is:
In FAR, the replacement code is:
I put the groups I reference in bold.
I knew you'd want to know...
To do a multi-line regex in FAR, precede find code with (?s).
Interestingly, this works in Flare as well. Flare's find (in the text editor itself) has the added advantage of showing you what it's matched with the regex. (FAR just does it, which is a little disconcerting.) So you can do a Find-and-Replace on all files in Flare and see what each match is going to replace with Find Next.
Flare has one oddness in the replacement side.
Background - Regex can find and store stuff into groups, and you use the groups you want.
For example,
Code: Select all
<h1>(.*?)</h1>(.*?)<table>
Most Regex implementations allow you to use a "$" to reference a group in a replacement string. So you might use the above like this:
Code: Select all
<h1>Description:</h1><h2>$1</h2>$2
Flare requires you to use a backslash to reference the group rather than a dollar sign:
Code: Select all
<h1>Description:</h1><h2>\1</h2>22
I also couldn't find a way for Flare to insert a newline as part of the replacement string.
In case anyone's interested, my code for finding an image and an H1 contained within a table that immediately follows a <body. tag (which is what I'm trying to replace) is:
Code: Select all
(?s)<body>(.*?)<table(.*?)<img(.*?)src="[b](.*?)[/b]"[b](.*?)[/b]/>(.*?)<h1>[b](.*?)[/b]</h1>(.*?)</table>
Code: Select all
<body>
<img src="$4" $5 />
<h1>$7</h1>
I knew you'd want to know...
-
- Senior Propellus Maximus
- Posts: 2632
- Joined: Wed Apr 14, 2010 8:01 am
- Location: Surrey, UK
Re: Find and replace with regular expressions
I'm on version 5.9.0, so you've got a very old version - I suggest you update!BobMerrill wrote:I just looked for that control, and haven't found it in version 2.01.
Started as a newbie with Flare 6.1, now using Flare 2023.
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
ChoccieMuffin, I'm probably missing something, but the latest version I could find was 2.02. This was searching on "FAR Find and Replace".
Thoughts welcome.
Bob
Thoughts welcome.
Bob
Re: Find and replace with regular expressions
<waves hand> This is not the FAR you are looking for.
:p
This is the one:
http://www.helpwaregroup.com/products/far
(And would explain some of the confusion.)
:p
This is the one:
http://www.helpwaregroup.com/products/far
(And would explain some of the confusion.)
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
Hmm. This version of FAR (5.10), while seeming QUITE capable, fast, flexible, and efficient, doesn't support regular expressions. Unless I'm missing something. The task we are trying to accomplish definitely requires something with the power of regular expressions.
Please let me know if I'm missing something!
And thanks for all the help so far...
Bob
Please let me know if I'm missing something!
And thanks for all the help so far...
Bob
-
- Propellus Maximus
- Posts: 1238
- Joined: Mon Feb 27, 2006 5:56 am
- Location: Melbourne, Australia
Re: Find and replace with regular expressions
This is the ?FAR that use (and I think ChoccieMuffin as well)
http://www.helpware.net/FAR/help/hh_start.htm
The download page is:
http://www.helpwaregroup.com/products/far
http://www.helpware.net/FAR/help/hh_start.htm
The download page is:
http://www.helpwaregroup.com/products/far
Margaret Hassall - Melbourne
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
That's the one I downloaded. It doesn't appear that it supports regular expressions. If someone thinks that isn't true, please let me know. I couldn't find a way to get it to use them...
Re: Find and replace with regular expressions
I use FAR (HTML), and it doesn't support regex - but did anyone say that it did?
It's more or a tool for people who don't know regex.
It's more or a tool for people who don't know regex.
-
- Propeller Head
- Posts: 45
- Joined: Tue Nov 07, 2006 10:17 am
- Contact:
Re: Find and replace with regular expressions
Dave,
I also have an earlier FAR that does support regex. Someone suggested I upgrade so I did. I incorrectly assumed it also supported regex. Thanks for clarifying!
Bob
I also have an earlier FAR that does support regex. Someone suggested I upgrade so I did. I incorrectly assumed it also supported regex. Thanks for clarifying!
Bob