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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
/(\xFF\xD8 .*? \xFF\xD9)/
Like a great friend of mine, you do talk a lot off track!

But your example is absolutely correct :-) This _is_ backtracking. However, it is exactly equivalent to
/(\xFF\xD8 .*? (?>\xFF\xD9))/
So, in a sense, it isn't _actually_ backtracking. Complicated backtracking would be when you cannot do that.

On to the future: one oft repeated mantra at the Monastery and elsewhere is that regexen are not well suited to parse HTML and XML, which is perfectly true. But under Perl 6 they will be so enhanced as to be promoted to "rules" which in turn, it is said, will be perfectly apt at implementing real parsers (although I'm not an expert, and not even a beginner, in parsing theory and I don't know which kind of parsers...) Ain't this a real-life problem?
Indeed, parsers are real life problems. And I did realize that in PerlFAQ there is an entry:
Can I use Perl regular expressions to match balanced text?

That's "real life" enough.

You'll realize though, that when you're parsing (complicated) languages, you'll need to do things like error checking. So, in practice, either you'll need to make the regex un-humanly complex, or it still must contain "outlets" in form of function callbacks etc. in order to handle special conditions and the logic and semantics of the language that you're parsing.

I can see that the regex features mentioned above are useful, but I still don't feel very cozy about their beauty and simplicity. It _is_ however clear, that Perl will be at least as useful (and better) than traditional parsers (yet probably not quite as fast, unless you really understand internal implementation issues.

Thanks a lot for bringing up these thoughts.


In reply to Re^2: Perl regex in real life by RezaRob
in thread Perl regex in real life by RezaRob

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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2019-08-24 18:15 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found