PDA

View Full Version : Any Regex gurus out there? (regular expression)



Comet
08-27-2008, 04:04 PM
Usually I can piece something together by trial and error without deep regular expression syntax expertise, but I am thrashing on this pattern:

"for example in <a href="../bible/2ki019.htm#2">2 Kings 19:2</a>; <a href="../bible/2ch026.htm#22">2 Chronicles 26:22</a>; <a href="../bible/2ch032.htm#20">32:20-32</a>, it is read"


The "after" result would look as follows:

"for example in 2 Kings 19:2; 2 Chronicles 26:22; 32:20-32, it is read"

Thanks,
Steve

Michael Hanel
08-27-2008, 04:27 PM
Usually I can piece something together by trial and error without deep regular expression syntax expertise, but I am thrashing on this pattern:

"for example in <a href="../bible/2ki019.htm#2">2 Kings 19:2</a>; <a href="../bible/2ch026.htm#22">2 Chronicles 26:22</a>; <a href="../bible/2ch032.htm#20">32:20-32</a>, it is read"


The "after" result would look as follows:

"for example in 2 Kings 19:2; 2 Chronicles 26:22; 32:20-32, it is read"

Thanks,
Steve

I am using Word:
make sure to check the box "use wildcards" in Search options

Find replace #1
Find: \<a href="../bible*"\>
replace: (space or nothing)

Find replace #2
Find: \<\/a\>
replace: (space or nothing)

Comet
08-27-2008, 04:43 PM
Thanks for the quick reply. The problem is that there are other </a> tags other than the bible ones.

But you gave me a good idea that I should probably try FAR or another editor with search and replace built in rather than trying to roll my own expressions with perl scripts.

Thanks,
Steve

Michael Hanel
08-27-2008, 04:53 PM
Thanks for the quick reply. The problem is that there are other </a> tags other than the bible ones.

But you gave me a good idea that I should probably try FAR or another editor with search and replace built in rather than trying to roll my own expressions with perl scripts.

Thanks,
Steve

Well see you didn't say it was *that* tricky :) Off the top of my head, if you use FAR, simply modify the start and end point so that it begins sniffing at "\<a href="../bible", marks a stop of one variable at ""\>", then goes all the way to "\<\/a\>", but keeps the text in the middle. FAR is pretty good at searches like that, but be sure to back up your text before you start playing around. I've made that mistake a few times before!

Comet
08-27-2008, 05:20 PM
Yes, I am going over the FAR docs now. I'll get it now.
Thanks!
Steve

Comet
08-27-2008, 05:39 PM
OK, got it with FAR. You can use the $0-$ that will replace the current match without the defined start and end.

Pretty amazing tool.

Yes, I copy backups all over the place with foldernames that identify their "state".

Steve