Quantcast
Channel: MobileRead Forums
Viewing all articles
Browse latest Browse all 50094

Odd regex problem

$
0
0
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?

Viewing all articles
Browse latest Browse all 50094

Latest Images

Trending Articles



Latest Images