Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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).


In reply to Re: Most specific pattern by jhourcle
in thread Most specific pattern by thor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2024-04-16 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found