Thread: Regex examples
View Single Post
Old 06-22-2020, 07:19 AM   #645
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
Is it possible to make a regex to turn a phrase with "fake small caps" into a sentence-case phrase, whilst also handling the occasional capitalised proper name in the middle? It must:
1. remove the spans;
2. put all the text between the spans into lower case, leaving the letters outside the spans in upper case;
3. (this is the tricky part) there may be one span on the whole phrase OR there may be several on different parts of the phrase, so it may be necessary to do a multi-part regex.

Example:
Find this:
Code:
<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">OTHER</span> <span class="Cap">W</span><span class="SmallCap">WORDS IN THE SENTENCE MAY OR MAY NOT BE CAPITALISED</span>
Turn it into this:
First word of the sentence is always capitalised, Other Words in the sentence may or may not be capitalised


If there is just one span I can manage it but since there can be two or three (or potentially more) spans I am not sure how to manage those possibilities.
Mister L is offline   Reply With Quote