Need help with regex Chinese numbers
-
Hello there, I’m sorry for my bad at English, but I really need you guys for help.
I have a bunch of novel text have this problem, example like this:
第一章 <-(this mean Chapter 1,章 mean Chapter, 第 not really important) 第八十一章 <-(this mean Chapter 81)
I want to change the construct of text from:
第一章 to 章:一 第八十一章 to 章:八十一
Many thanks.
-
@Bạch-Lão-Bản
may be test something like the following:
Search pattern:(第)([八十一])+(章)
Replacement pattern:
\3:\2
You will have to add more numbers to the list in the middle of the search pattern.
See https://regexr.com/ or any other regular expression page for detailed information. -
Hello, @bạch-lão-bản, @Stefan-pendl and All,
Not difficult with regular expressions ! Basically, you have this kind of text :
- The
第
char, then a range, possibly null, of character(s), then the一章
characters
And you expect :
The
章:
char, followed with this same range of char(s) and ending with the一
char
In regex language, this can be coded as :
SEARCH
(?-s)第(.*)一章
REPLACE
章:\1一
So :
-
Open the Replace dialog (
Ctrl + H
)-
SEARCH
(?-s)第(.*)一章
-
REPLACE
章:\1一
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Click once the
Replace All
button or hit theAlt + A
shortcut
-
-
Close the Replace dialog (
Esc
)
Notes :
-
The
(?-s)
part forces the regex engine to consider any dot regex symbol (.
) as matching a single standard character ( notline-break
ones ! ) -
Then, the part
.*
represents any, possibly null, range of standard characters, between the第
char and the一
char. As it is embedded between parentheses, it is stored and can be re_used, either in the Search regex part with the\1
syntax or in the Replace regex part with the\1
or$1
or${1}
syntaxes -
The four characters
第
,章
,:
and一
are just literal chars to be searched and replaced as it is !
Best Regards,
guy038
- The
-
Thank you, this problem finally solved :D