in reply to Re^3: why my reg ex matches greedy?
in thread why my reg ex matches greedy?
And I thought the \d{11,}? was the invented bit. I'll have to play with that sometime.
You should, the future of all new perl regex features rests upon that syntax
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: why my reg ex matches greedy?
by roboticus (Chancellor) on Jun 26, 2012 at 12:14 UTC | |
I don't see the relation between your link and that bit of the regex. However, that said, your skepticism of its utility seems justified. I tried to find a use for it, but I haven't been able to make \d{4,}? act any differently than \d{4}. It's either a useless construct, or a failure of my imagination in coming up with an appropriate test case. Putting aside what YAPE::Regex::Explain says about it, when I looked at it originally, I thought "Yack! Perl is gonna bitch about that weird '?' character". I could think of a couple other interpretations, so I put together a bit of code to check 'em out:
The other interpretations I could think of were:
On reading the ...explain() output, I thought that I could perhaps make the third case come about. But what I actually got was:
So I'm thinking that my initial surprise was justified, even though it's syntactically correct. ...roboticus When your only tool is a hammer, all problems look like your thumb. | [reply] [d/l] [select] |
by GrandFather (Saint) on Jun 26, 2012 at 21:01 UTC | |
It's different if there is some following match condition:
Prints:
True laziness is hard work
| [reply] [d/l] [select] |
by roboticus (Chancellor) on Jun 26, 2012 at 22:27 UTC | |
Thanks. I updated your code to make it a little more visually obvious to me, then added a couple cases. Now that I see what the difference is, I doubt that I'd ever use it. Not because it isn't useful, but rather because if I ever need it, I'm sure I'll have long forgotten it. But it's certainly educational. For grins, here's what I came up with:
(As you can tell, I like things laid out in grids. I organize lots of stuff with database tables and spreadsheets...) ...roboticus When your only tool is a hammer, all problems look like your thumb. | [reply] [d/l] |