Find and replace with regular expressions

This forum is for all Flare related Tips and Tricks.
Have a tip or trick you use while working in Flare? Share it here.

Find and replace with regular expressions

Postby Dinnit on Tue May 17, 2016 12:16 am

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
Ann
Started on Flare 3, now on Flare 2017 r2 + Capture (occasionally) and Analyser (very occasionally)
Windows 10 Enterprise
Dinnit
Propeller Head
 
Posts: 85
Joined: Tue Nov 13, 2007 5:51 am
Location: Stroud, Glos, UK

Re: Find and replace with regular expressions

Postby BobMerrill on Wed Oct 31, 2018 7:12 am

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 :o) but also doesn't seem to support multi-line matching.
Thanks for any thoughts.
Best,
Bob
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby ChoccieMuffin on Wed Oct 31, 2018 10:27 am

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 2018.
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
ChoccieMuffin
Propellus Maximus
 
Posts: 1832
Joined: Wed Apr 14, 2010 8:01 am

Re: Find and replace with regular expressions

Postby BobMerrill on Wed Oct 31, 2018 11:29 am

Thanks so much! I missed that control... This may be our salvation!
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby BobMerrill on Thu Nov 01, 2018 6:37 am

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 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.
I'm not a FAR expert, so I could easily have missed something.
Thanks for any thoughts!
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby BobMerrill on Thu Nov 01, 2018 6:49 am

Found it:
http://findandreplace.sourceforge.net/documentation/manual21-faq.html

There is an FAQ on multiline. It's a regex control, not a FAR UI control...
Best,
Bob
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby BobMerrill on Thu Nov 01, 2018 9:15 am

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,
Code: Select all
<h1>(.*?)</h1>(.*?)<table>

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:
Code: Select all
<h1>Description:</h1><h2>$1</h2>$2


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:
Code: Select all
<h1>Description:</h1><h2>\1</h2>22

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:
Code: Select all
(?s)<body>(.*?)<table(.*?)<img(.*?)src="[b](.*?)[/b]"[b](.*?)[/b]/>(.*?)<h1>[b](.*?)[/b]</h1>(.*?)</table>


In FAR, the replacement code is:
Code: Select all
<body>
<img src="$4" $5 />
<h1>$7</h1>


I put the groups I reference in bold.

I knew you'd want to know... :D
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby ChoccieMuffin on Thu Nov 01, 2018 10:36 am

BobMerrill wrote:I just looked for that control, and haven't found it in version 2.01.


I'm on version 5.9.0, so you've got a very old version - I suggest you update! :D
Started as a newbie with Flare 6.1, now using Flare 2018.
Report bugs at http://www.madcapsoftware.com/bugs/submit.aspx.
Request features at https://www.madcapsoftware.com/feedback ... quest.aspx
ChoccieMuffin
Propellus Maximus
 
Posts: 1832
Joined: Wed Apr 14, 2010 8:01 am

Re: Find and replace with regular expressions

Postby BobMerrill on Fri Nov 02, 2018 9:05 am

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
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby Psider on Sun Nov 04, 2018 10:47 pm

<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.)
Psider
Sr. Propeller Head
 
Posts: 466
Joined: Wed Jul 06, 2011 1:32 am

Re: Find and replace with regular expressions

Postby BobMerrill on Mon Nov 05, 2018 8:37 am

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
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby wclass on Mon Nov 05, 2018 2:02 pm

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
Margaret Hassall - Melbourne
wclass
Propellus Maximus
 
Posts: 1201
Joined: Mon Feb 27, 2006 5:56 am
Location: Melbourne, Australia

Re: Find and replace with regular expressions

Postby BobMerrill on Mon Nov 05, 2018 6:31 pm

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...
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am

Re: Find and replace with regular expressions

Postby Dave Lee on Tue Nov 06, 2018 12:50 am

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.
Dave Lee
Master Propellus Maximus
 
Posts: 5368
Joined: Mon Mar 05, 2007 8:33 am
Location: UK

Re: Find and replace with regular expressions

Postby BobMerrill on Tue Nov 06, 2018 5:55 am

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
BobMerrill
Propeller Head
 
Posts: 45
Joined: Tue Nov 07, 2006 10:17 am


Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 4 guests