|
|
10-25-2011, 12:49 PM | #1 |
Member
Join Date: Aug 2005
Location: Arlington, VA (across the river from Washington, DC)
Posts: 560
|
RegEx help needed to close <p> tags.
Hey, folks, long time no see. How's everyone been?
My office is currently doing a full redesign and, unlike the last time ~10 years ago, we're moving from static HTML to a really cool CF system we built in house. Some of the pages we're converting haven't been touched in more than a decade so we have a lot of re-coding to do to get them to validate to current standards. We have shortcuts for most of the fixes, but one of the most time consuming is fixing pages where the <p> tags don't have corresponding </p> tags. Is it possible to write a RegEx that can look for a <p> tag, look for the NEXT <p> tag, and insert a </p> if there isn't one there? Ideally, ignoring white space. We have Dreamweaver, HomeSite, and TextPad available so please specify if the RegEx is tool-specific. Thanks, Dennis __________________ Dennis |
10-25-2011, 02:15 PM | #2 |
Member
Join Date: Feb 2005
Location: some room with white padded walls ... now surrounded by Saguaro Cacti
Posts: 352
|
It may be easier to blindly inject </p> before each <p> (yielding </p><p> ... simple to do that, of course). Then, search for the inversion case (i.e., \<p\>(.+)\<\/p\>(.*)(\<\/p\>)\<p\> ) removing the second </p> with <p>\1</p>\2<p>.
The "i.e.," RE is just dumped from my head so *don't* feel free to blindly copy/paste (followed by something stupid like change all, save all /w no prompts). ; Last edited by curveto; 10-25-2011 at 02:16 PM. Reason: more detail |
10-25-2011, 02:25 PM | #3 |
Member
Join Date: Aug 2005
Location: Arlington, VA (across the river from Washington, DC)
Posts: 560
|
I think that may be an approach we hadn't considered. Without RegEx, we've done search/replace on <p> and replacing with </p><p>, then fixing fewer errors. I'll pass this on to my scripter, but what tool was the RE written for? I'm a novice on RE after many years, but I know Dreamweaver requires different syntax than HomeSite.
__________________ Dennis |
10-25-2011, 02:29 PM | #4 |
Member
Join Date: Feb 2005
Location: some room with white padded walls ... now surrounded by Saguaro Cacti
Posts: 352
|
That RE (sample) just came out of my brain (which is generally a mental mixture of Visual Studio and BBEdit).
...the ()s mark something for later re-insertion via \1 \2, etc. Some tools use {} and /1 /2 or other things... |
10-26-2011, 01:37 AM | #5 |
Member
Join Date: Aug 2005
Location: Arlington, VA (across the river from Washington, DC)
Posts: 560
|
I have a developer on my team that knows how to write REs and this might be enough to get him started. He was just stumped on the approach.
__________________ Dennis |
10-26-2011, 08:09 PM | #6 |
Member
Join Date: Jan 2005
Location: Los Angeles, Ca.
Posts: 942
|
Seems to me my copy of DW automatically corrects that sort of error when I open a mal-formed file.
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Regex Question | Andrew B. | General Publishing Topics | 2 | 09-20-2011 07:46 PM |
Need Regex help | Andrew B. | General Publishing Topics | 7 | 05-08-2011 08:56 AM |
RegEx help | dacoyle | Web Site Building & Maintenance | 6 | 04-14-2009 07:48 AM |
meta tags and leading one on...'-}} | terrie | Web Site Building & Maintenance | 4 | 08-09-2006 02:02 PM |
Useful info on meta tags | ktinkel | Web Site Building & Maintenance | 3 | 04-22-2005 12:37 PM |