tcepsa: (I'll fix it!)
[personal profile] tcepsa
I just gained at least one, possibly two levels in Regular Expressions.

I'm all tingly now... ^_^

Date: 2008-04-04 01:50 am (UTC)
ext_12535: I made this (Default)
From: [identity profile] wetdryvac.livejournal.com
*cues up some Jackelope as victory music*

Congrats! What earned you the levels?

*curious look*

Mmm, I do so love 'em. Always interested to see what people are doing.

Date: 2008-04-04 02:42 am (UTC)
From: [identity profile] tcepsa.livejournal.com
Caveat 1: This puts me at approximately Level 3, assuming I started at Level 1 ~wry grin~ so there's probably plenty of room for improvement with these and I'd love to hear your suggestions.

Caveat 2: I'm reproducing this from memory at 10:30 after not getting a whole lot of sleep yesterday night. It's a good exercise in seeing whether I can still catch all the little gotchas that I thought of while writing it earlier, but I may not be entirely successful.

It was a multi-file (facilitated by Eclipse) search as follows
(preliminary searches to determine whether I need to make it really complicated):
<[^<>]*\s[sS][tT][yY][lL][eE][^<>]*\s[aA][lL][iI][gG][nN]\s*=[^<>]*>
<[^<>]*\s[aA][lL][iI][gG][nN]\s*=[^<>]*\s[sS][tT][yY][lL][eE][^<>]*>

These two check for html tags with both style and align attributes (couldn't figure out a way to check for a style attribute before OR after the align attribute in the same regex) [side note: do you prefer 'regex' or 'regexp' for the abbreviation?]

These both came back with no matches, leading me to conclude that there were no tags containing both a style attribute and an align attribute, making the next part much simpler...

Actual Search:
(<[^<>]*)(\s[aA][lL][iI][gG][nN]\s*=\s*(\\?['"]?)[cC][eE][nN][tT][eE][rR]\3([^<>]*>)

Replace:
$1 style=$3text-align:center;$3 $4

Thereby replacing all no-longer-standards-adherent align attributes with a standards-compliant style attribute that would preserve any escaping of quotes and still be valid (though slightly less standards-compliant) even if there were no quotes. (Valid in the sense that it shouldn't actually cause anything to break if there aren't any quotes in the $3 regex match)
Edited Date: 2008-04-04 02:43 am (UTC)

Date: 2008-04-04 02:47 am (UTC)
ext_12535: I made this (Default)
From: [identity profile] wetdryvac.livejournal.com
Ooo, shiny! And with the example in place so I can see it... very cool. Thanks!

*hands you a L3 badge*

Date: 2008-04-04 02:45 pm (UTC)
From: [identity profile] tcepsa.livejournal.com
~accepts badge solemnly, replaces L1 badge with it~

~grin~ Thank you ^_^

Also, I checked against the actual thing that I used, and the only difference was that in the actual one I had also provided for the possibility of there being zero or more whitespace characters inside the quotes, so "  ceNtER " would have matched.

Profile

tcepsa: (Default)
tcepsa

April 2015

S M T W T F S
   12 34
567891011
12131415161718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 3rd, 2025 10:10 am
Powered by Dreamwidth Studios