|
|
Help Me Grep, Please
|
|
|
|
Fresh-Faced Recruit
Join Date: Dec 2002
Location: Oxford
Status:
Offline
|
|
I've got BBEdit open. I've got a webpage full of entries like this:
<strong>Anti-Slavery International</strong> - <a href="http://www.antislavery.org">http://www.antislavery.org</a>
– ASI is the oldest human rights organization in world and the sister
organization to Free the Slaves, based in London, England.
I want to change this to:
<dt><a href="http://www.antislavery.org">Anti-Slavery International</a></dt><dd>ASI is the oldest human rights organization in world and the sister organization to Free the Slaves, based in London, England.</dd>
This would take hours to do by hand, but I know there's a quick solution using BBEdit's grep search and replace feature. After trying out different patterns for half an hour or so, I haven't been having much luck.
Can anyone here help me?
Thanks,
JP
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status:
Offline
|
|
Try something like:
Find:
<strong>(.*)</strong>.*(<a href.*?>).*</a>([^<]*)
Replace with:
<dt>\2\1</a></dt>\r<dd>\3</dd>\r
(obviously with "Use grep" ticked!). It's far from perfect, but it might get the job done. Parsing html is usually in imperfect sort of operation.
Best of luck,
Paul
|
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Dec 2002
Location: Oxford
Status:
Offline
|
|
Thanks, Paul. Your solution worked out well, although I had to escape the brackets and slashes with backslashes--only those outside of the parentheses, though. Curious.
You definitely saved me a few hours of tedious editing. Thanks again.
-JP
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status:
Offline
|
|
No problem whatsoever! Glad to hear that you got there in the end.
I'm still a bit confused as to the escaping business however; works fine in BBEdit 6.5.3 as printed in my post above (for what it's worth). I guess they've just changed the rules for what counts as a metacharacter through the different versions.
Best wishes,
Paul
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status:
Offline
|
|
Originally posted by immsav:
I've got BBEdit open. I've got a webpage full of entries like this:
<dt><a href="http://www.antislavery.org">Anti-Slavery International</a></dt><dd>ASI is the oldest human rights organization in world and the sister organization to Free the Slaves, based in London, England.</dd>
While you are at it, you should correct a grammatical mistake you made in both versions - "ASI is the oldest human rights organization in the world and ..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|