Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Perl Complains of Nested Quantifiers

by roboticus (Chancellor)
on May 22, 2012 at 15:50 UTC ( #971816=note: print w/replies, xml ) Need Help??

in reply to Perl Complains of Nested Quantifiers


Update: Obviously, I should've tested my theory before shooting off my mouth. ww gave it a try (nice catch!) and didn't see the problem, when I tried, I couldn't reproduce either.

The problem is that you're asking for "one or more one or more digits". You either mean one or more digits, or one or more digits followed by a '+':

/(\d+\.\d+)/oi; # One or more digits /(\d+\+\.\d+\+)/oi; # One or more digits with '+'

Since you mention greediness, you might mean to not take too many items from the string. However, since you're taking only digits and have a literal '.' between them, I don't know what you'd really mean. (\d+? doesn't make any sense, unless it were something like \d+?7, for example.)


When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^2: Perl Complains of Nested Quantifiers
by sunmaz (Novice) on May 22, 2012 at 16:14 UTC

    I wish to match the same as the following regex would (you can ignore the scalar at the end of my pattern - it is just a substitution for a simple search string): /(\d+\.\d+)($meanSearchTerm)/oi. That is it matches strings of the form: floating point numbersearch string. I simply wish to modify the greedy quantification to possessive to prevent any chance of catastrophic backtracking. Thus I do not intend to quantify the quantifier (as perl naively assumes).

      Is the backtracking "catastrophic," in this case, due to a possible increased matching time by a greedy regex?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971816]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2018-08-17 05:42 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (174 votes). Check out past polls.