General questions about using TextPad
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
terrypin
- Posts: 174
- Joined: Wed Jul 11, 2007 7:50 am
Post
by terrypin »
The source text looks like this:
00_c_People\
00_c_SimpleBlue\
2006_Audio\
2006_AutoDefault\
I want it like this:
People\
SimpleBlue\
Audio\
AutoDefault\
Using
Find (.*)_(.*)
Replace with \2
I expected it to fail for the first two lines, delivering:
c_People\
c_SimpleBlue\
Audio\
AutoDefault\
But to my surprise it gave the correct result.
Is that because it looks for the underscore from right to left, rather than left to right as I'd assumed? Or some other explanation?
--
Terry, East Grinstead, UK
-
MudGuard
- Posts: 1295
- Joined: Sun Mar 02, 2003 10:15 pm
- Location: Munich, Germany
-
Contact:
Post
by MudGuard »
* is greedy. Thus the first (.*) takes up as much as possible without breaking global match.
For the first two lines, the first
(.*) matches 00_c.
To make it non-greedy, you have to use *? instead.
-
ak47wong
- Posts: 703
- Joined: Tue Aug 12, 2003 9:37 am
- Location: Sydney, Australia
Post
by ak47wong »
Moreover, you can accomplish the same result more simply with this:
Find what: .*_
Replace with: [nothing]
-
terrypin
- Posts: 174
- Joined: Wed Jul 11, 2007 7:50 am
Post
by terrypin »
Thanks both.
.*_ does indeed do the job very neatly!
--
Terry, East Grinstead, UK