![]() |
#1 |
Enthusiast
![]() Posts: 42
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}]*))? Code:
\1\L\2\4\5\L\6 Code:
\1|\L\2|\4|\5|\L\6 Code:
T|wenty|-|t|hree |
![]() |
![]() |
![]() |
#2 |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 20,704
Karma: 27405072
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
No idea from a technical perspective, but "Twenty-three" is the de-facto standard for Chapter numbers expressed in words - hyphenated sentence case.
BR |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 27,629
Karma: 194783560
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
You need to use an \E to terminate an \L or \U otherwise they'll just keep going. So I would suggest an \E immediately after the capture group that represents the '-' in the replace expression (or before it).
\1\L\2\E\4\5\L\6 Or: \1\L\2\4\E\5\L\6 I'm not at a computer where I can test the replace expression exactly. I also think you don't need the brackets [] around each individual \p{Lu} instance. Last edited by DiapDealer; 11-16-2023 at 09:29 PM. |
![]() |
![]() |
![]() |
#4 | |
Enthusiast
![]() Posts: 42
Karma: 10
Join Date: Jul 2023
Device: none
|
Quote:
|
|
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 27,629
Karma: 194783560
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
In our user guide? I doubt it. We only give the briefest of intros to regex. But I'm sure it's in any thorough documentation for the PCRE flavor of regex.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 37,009
Karma: 148321038
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Odd link problem | Julanna | Conversion | 10 | 06-19-2014 03:19 AM |
PRS-T1 Odd USB problem | TAG_Keri | Sony Reader | 12 | 07-16-2013 01:00 AM |
Odd Problem | Pope Viper | Library Management | 3 | 06-23-2011 12:16 PM |
Odd problem with Sigil 0.4 | bobcdy | Sigil | 7 | 06-23-2011 02:45 AM |
Odd conversion problem | speakingtohe | Calibre | 2 | 05-10-2010 10:18 AM |