Hi,
I've always thought that if I put a "?" after a search expression, that it would stop after the first instance of something. Doesn't seem to work for me, because, the whole line gets selected instead of just the first instance.
search <employee>(.*)?
gives me the whole line instead of just the first name.
Thanks,
Peter
greedy regexes
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
TextPad's regex recogniser is old and weak, and many constructs supported by modern tools do not work in TextPad. In particular, TextPad's regex recogniser doesn't support non-greedy repetition operators (such as *?).
Note that your regex (.*)? does not contain a non-greedy repetition operator: it's just an optional occurrence (?) of any number (possibly zero) (*) of occurrences of any character (.). It's equivalent to .* (except that it's slower).
The non-greedy forms of the operators, where they are supported, are *?, +? and ?? (without intervening parentheses).
What are you trying to do?
Note that your regex (.*)? does not contain a non-greedy repetition operator: it's just an optional occurrence (?) of any number (possibly zero) (*) of occurrences of any character (.). It's equivalent to .* (except that it's slower).
The non-greedy forms of the operators, where they are supported, are *?, +? and ?? (without intervening parentheses).
What are you trying to do?
greed and non-greedy regexes
Thanks, Ben. My example wasn't very good. I'm trying to parse through a comma-delimited Excel file, to try and make it into XML. So, I was trying to capture the first object in the line, in this case "employee," followed by its content, up to the beginning of the second object. So, your description helps me. I was just doing it wrong. I probably need "*?."
Thanks again,
Peter
Thanks again,
Peter
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
greed and non-greedy regexes
Probably. I'm at home now. I do this stuff at work. When I'm back to work Monday I'll try that. That looks correct.