Retaining capitalization in regex
Posted: Fri Jun 24, 2011 2:25 pm
Hello,
Struggling with this: I need to reformat multiple instances of similar tags, from:
<script>document.write(FOOBAR)</script>foobar
or:
<script>document.write(BARGLE)</script>Bargle
to:
<a href="event:Foobar">foobar</a>
and:
<a href="event:Bargle">Bargle</a>
However I can't seem to get any regex syntax that'll retain the occasional initial capitalization.
I had hoped that [:alnum:] would automatically retain the capitals, but no.
So I've tried ([[:alnum:]]*), ([a-z0-9]*) and ([A-Za-z0-9]*), no success, either with match case on or off.
Tried ([A-Z]?[a-z0-9]*), hoping the 'zero or one' operator would pick up the initial caps and default to the lowercase string where none is present. When I do this with Match Case off, it mirrors the previous behaviour, with Match Case on it retains the initial capital, but leaves the foobar/Bargle string *outside* the closing </a> tag.
I'm sure there's something really quite basic I'm missing here, or is it simply that there's no way to retain lettercase in this manner?
Struggling with this: I need to reformat multiple instances of similar tags, from:
<script>document.write(FOOBAR)</script>foobar
or:
<script>document.write(BARGLE)</script>Bargle
to:
<a href="event:Foobar">foobar</a>
and:
<a href="event:Bargle">Bargle</a>
However I can't seem to get any regex syntax that'll retain the occasional initial capitalization.
I had hoped that [:alnum:] would automatically retain the capitals, but no.
So I've tried ([[:alnum:]]*), ([a-z0-9]*) and ([A-Za-z0-9]*), no success, either with match case on or off.
Tried ([A-Z]?[a-z0-9]*), hoping the 'zero or one' operator would pick up the initial caps and default to the lowercase string where none is present. When I do this with Match Case off, it mirrors the previous behaviour, with Match Case on it retains the initial capital, but leaves the foobar/Bargle string *outside* the closing </a> tag.
I'm sure there's something really quite basic I'm missing here, or is it simply that there's no way to retain lettercase in this manner?