Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Regexp Confuzzelemt

by akho (Hermit)
on Apr 27, 2007 at 21:41 UTC ( #612461=note: print w/replies, xml ) Need Help??

in reply to Regexp Confuzzelemt

Regular expressions are greedy by default. That means (.*[^\?]) first matches the whole input for .*, backtracks one character and matches "c" for [^\?].

You want #(.*?)\? (the '?' makes the .* non-greedy).

#([^?]*) also works, of course. But it also matches "TTT" in "aaaaaaaa#TTT" (note that there is no question mark).

Replies are listed 'Best First'.
Re^2: Regexp Confuzzelemt
by ikegami (Pope) on Apr 28, 2007 at 02:37 UTC

    But it also matches "TTT" in "aaaaaaaa#TTT"

    That's a difference you introduced. If you put the \? back in, it won't.
    is equivalent to

    The latter is safer. It's easy to introduced problems when using non-greedy quantifiers. They're not as resilient. For example, you can safely embed the greedy regexp in a larger regexp, but you can't safely embed the non-greedy regexp in a larger regexp.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://612461]
[marto]: Eily, there's actually a lot of good discussion on the topic in the HN link choroba posted
[marto]: sorry for the late response, busy busy :/
[Corion]: I think you need to load Readline in the debugger, but I don't know how
[Corion]: Yay, invitation for a team-building workshop, with a team of 100 people :-/
[Eily]: marto after an additional read I started to see the light actually. And choroba's link was helpful as well :)
[Corion]: I'll send my colleague who doesn't yet know the people there, and I'll do production duty instead.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2017-07-26 15:01 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (396 votes). Check out past polls.