Thread: Regex examples
View Single Post
Old 09-16-2016, 03:58 PM   #508
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,630
Karma: 204624552
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Psymon View Post
For my regex search I initially came up with this...

<span class=\"initial\">(.+?)</span>([^>]*)\s
Try this instead:
Code:
<span class="initial">(.+?)</span>(\w*)
You don't need to escape the quotation marks in your search criteria. The \w will match only word characters, which means it will stop before any punctuation that might occur (an apostrophe in the word you want to smallcap will trip this up).

If any unicode characters can be expected, you may want to make the \w unicode-aware with the (*UCP) command.
Code:
(*UCP)<span class="initial">(.+?)</span>(\w*)
The (.+?) part can be a bit greedy. If one letter is all that's ever expected, I'd probably use (\w) instead.
Code:
(*UCP)<span class="initial">(\w)</span>(\w*)
If an opening quote may be in the raised|dropped cap as well, then explicitly include it (making it optional of course):
Code:
(*UCP)<span class="initial">(“?\w)</span>(\w*)
Probably gonna play hell on one-letter drop|raised-cap words, too ("I" and "A"), though.

Quote:
Originally Posted by Psymon View Post
...and for replace this...

<span class="initial">\1</span><span class="smallcaps">\U\2\E</span>
The replace should work fine as is.

To eliminate the issue of one-letter word drop/smallcaps, I'd probably do something like.
FIND:
Code:
(*UCP)<span class="initial">“?\w</span>\K(\w*)
REPLACE:
Code:
<span class="smallcaps">\U\1\E</span>
EDIT: None of the optional regex search options should be checked (other than maybe the "wrap" option) for any of my examples, by the way.

Last edited by DiapDealer; 09-16-2016 at 04:07 PM.
DiapDealer is offline   Reply With Quote