If he knows that the only other parentheses he is going to have in his data are not going to have quotes before or after them, is it more efficient to try to match less? Or is that not an issue?

Generally, it's not an issue. In fact, a regular expression that matches more might be more efficient in some circumstances¹. The only thing that can really cripple your efficiency is an expression which causes the regular expression engine to do a whole lot of backtracking.

For the most part, you really don't have to worry about regular expression efficiency at all but you will, on occasion, run into a situation where an understanding of it is invaluable. When you do have to worry about it, the way to approach it isn't to construct an expression which will match less but to construct an expression which will allow the engine to work less in determining whether a match exists or not.

1. E.g. You have to find all lines in a large file that contain the word "bar" but you also happen to know that all of the lines that contain the word "bar" will also start with "foo". You could use /^foo.*bar/ instead of /bar/ and, even though the expression matches more, you will quickly eliminate many lines. This is a contrived example but similar situations are not uncommon in real programming.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: Re: Re: stripping by sauoq
in thread stripping by wolverina

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.