Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Most specific pattern

by jhourcle (Prior)
on Jun 30, 2005 at 20:19 UTC ( [id://471461]=note: print w/replies, xml ) Need Help??


in reply to Most specific pattern

I don't think that it's necessarily a function of the pattern. It's a function of the process.

For instance, if there's a pattern that's more preferable to use, no matter if it's the shortest, or longest pattern, it should be tested first.

In much of the work that I do, I test against the patterns that are most likely to match, and then test all of the outlying conditions that I still know how to handle.

Typically, I find that longer regexes, although they might be more time consuming to match, are a more precise fit, and so I'd qualify them as 'better' in the types of processes that I deal with.

A few metrics that I can think of that I might use would be:

  • Most desired result
  • number of capturing parenthesis
  • Number of fixed (non-varying) characters.
  • Number of fixed characters, or zero-width items.
  • Odds of matching.
  • Number of characters, zero-width items, or character classes

There's probably dozens of other metrics ... I'd have to judge based on the process. Typically, I manually order things -- if regexA will match everything that regexB will match, but regexB won't match as much as regexA, I'd have to decide if there are different actions to be taken by the two, or if one outcome is preferable to the other.

Oh -- and a minor nitpick. /*/ matches an asterisk. /.*/ is zero or more characters (non-newlines, unless you add modifiers).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-03-29 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found