DeepBlueSea wrote:Stefan
RegEx-search for: (\d)\s(.+)
Replace: 0\1 \2
But
10 Chapter.txt becomes
00 Chapter.txt and
11 Chapter.txt becomes
01 Chapter.txt
That's what you are searching for whit this RegEx :D
We look for an digit with (\d)
following by an space with \s
So (\d)\s
on
35 Chapter.txt
match the digit 5 and the following space
and you should get
5 Chapter.txt when replacing with '\1 \2'
and
05 Chapter.txt when replacing with '0\1 \2'
You get with this RegEx '(\d)\s' always the digit just before the space.
But not the very first digit as we didn't catch them and so this digit is dropped.
If you then replace with '0\1 \2' you place the new zero digit
on the place of the dropped digit.
Did you read the regex help?
There you see you can search
for one
or more
or even an exactly occurrence of the expression you search for.
Look!
\d search for ONE digit.
\d* search for none or one or two or more digits
\d+ search for --------- one or two or more digits
You want to catch at least ONE digit (names without an starting digit we didn't want to rename, yes?)
But you also look for two or maybe three digits?
So use an expression like \d+
This \d+ will look for one or more digits.
\d => one
\d* => none or many
\d+ => one or many
\d\d => two
\d\d\d => three
\d{3} => three
\d(1,3) => at least one but up to three
\d(,3) => none or up to three
So i guess use
SEARCH: (\d+)\s(.+)
REPLACE: 0\1 \2
You can also experiment wit ^ and $
^ means the beginning of an string (or an name here)
$ means the end of an string
HTH?
If not please ask again.
Greetings to all