11-16-2023, 07:58 PM | #1 |
Enthusiast
Posts: 39
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 |
11-16-2023, 08:32 PM | #2 |
null operator (he/him)
Posts: 20,670
Karma: 26966376
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 |
11-16-2023, 09:18 PM | #3 |
Grand Sorcerer
Posts: 27,602
Karma: 193191846
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. |
11-17-2023, 12:41 AM | #4 | |
Enthusiast
Posts: 39
Karma: 10
Join Date: Jul 2023
Device: none
|
Quote:
|
|
11-17-2023, 05:27 AM | #5 |
Grand Sorcerer
Posts: 27,602
Karma: 193191846
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.
|
11-17-2023, 08:27 PM | #6 | |
Bibliophagist
Posts: 36,607
Karma: 146499190
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Quote:
|
|
|
Similar Threads | ||||
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 |