Thread: Regex examples
View Single Post
Old 06-22-2020, 01:02 PM   #647
Mister L
Groupie
Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Mister L is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Posts: 179
Karma: 91148
Join Date: Jun 2010
Device: Sony 350
Quote:
Originally Posted by Doitsu View Post
The following expression should do the trick:

Find:<span class="Cap">(.)</span><span class="SmallCap">(.*?)</span>
Replace:\1\L\2\E
Thanks, I use that one when there is only one span to remove, however it doesn't seem to work when there are several in the same phrase like in my example. I have checked "minimal match" but it still finds the first opening tag of the series and then the last closing tag, rather than each pair in succession.

Example:
<span class="Cap">F</span><span class="SmallCap">IRST WORD OF THE SENTENCE IS ALWAYS CAPITALISED,</span> <span class="Cap">O</span><span class="SmallCap">THER</span> <span class="Cap">W</span><span class="SmallCap">WORDS IN THE SENTENCE MAY OR MAY NOT BE CAPITALISED</span>

Desired result :
First word of the sentence is always capitalised, Other Words in the sentence may or may not be capitalised.

Actual result:
First word of the sentence is always capitalised,</span> <span class="cap">o</span><span class="smallcap">ther</span> <span class="cap">w</span><span class="smallcap">words in the sentence may or may not be capitalised

So I have lost some capital letters I want to preserve, and also for some reason even if I insert the cursor before the next opening tag of a complete pair, no other matches are found, and the code is broken.

I have not found any way to fix this other than doing it by hand, I really don't know if it's possible to do it with regex to be honest*.

Edit: *I should say, except by doing it in several passes, first
<span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span>

replace
\1\L\2\E \3\L\4\E \5\L\6\E

Then
<span class="Cap">(.)</span><span class="SmallCap">(.*?)</span> <span class="Cap">(.)</span><span class="SmallCap">(.*?)</span>

\1\L\2\E \3\L\4\E

Then just one pair.

But I'm interested to know if there is a way to manage all the cases in just one pass, in case you don't know in advance how many sets of spans there might be.

Last edited by Mister L; 06-22-2020 at 01:29 PM.
Mister L is offline   Reply With Quote