View Single Post
Old 11-16-2023, 07:58 PM   #1
jwes
Connoisseur
jwes began at the beginning.
 
Posts: 82
Karma: 10
Join Date: Jul 2023
Device: none
Odd regex problem

I wanted to change chapter numbers to title case, e.g. TWENTY to Twenty or TWENTY-THREE to Twenty-Three. I came up with these patterns
Find:
Code:
([\p{Lu}])([\p{Lu}]+)((-)([\p{Lu}])([\p{Lu}]*))?
Replace:
Code:
\1\L\2\4\5\L\6
It works for TWENTY, but it turns TWENTY-THREE to Twenty-three. As an experiment, I put '|'s in the replace string like this:
Code:
\1|\L\2|\4|\5|\L\6
and I got
Code:
T|wenty|-|t|hree
, so I can see it is being split correctly, but the T in three is being lowercased. Any explanations why?
jwes is offline   Reply With Quote