Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Any way to use "POSIX Extended Regular Expressions"?

by Lightknight (Sexton)
on May 21, 2010 at 10:13 UTC ( #841068=perlquestion: print w/ replies, xml ) Need Help??
Lightknight has asked for the wisdom of the Perl Monks concerning the following question:


I need some regexps to match consistently in perl and MySQL.

MySQL doesn't use Perl compatible regular expressions but "MySQL uses Henry Spencer's implementation of regular expressions".

And there is a way to use Perl compatible regular expressions in MySQL but that requires modification of the MySQL server, and I'd like to avoid that. I'm surprised I can't find a way (even on CPAN?) to use exactly "POSIX Extended Regular Expressions" in perl. (Which is not the same as /foo/x)

Am I missing something obvious? Is there a way to match against "POSIX Extended Regular Expressions" in perl?

Comment on Any way to use "POSIX Extended Regular Expressions"?
Re: Any way to use "POSIX Extended Regular Expressions"?
by moritz (Cardinal) on May 21, 2010 at 10:22 UTC
    Since version 5.10 perl supports pluggable regex engines, and there's re::engine::PCRE on CPAN that should pretty much do what you want.
      Thanks for your reply, but as I said in my original post: "MySQL doesn't use Perl compatible regular expressions"
      PCRE stands for "Perl Compatible Regular Expressions". Which used to implement a superset of Perl regular expression, but we have since (5.10) caught up.

      But the OP asked for POSIX regular expressions. Which, except for syntax differences, actually behave differently:

      "abc" =~ /.|../ && print $&;
      Prints 'a' with Perl, but a POSIX style regexp engine would result in 'ab' being printed. With POSIX style, "longest" trumps "leftmost".

      You must mean re::engine::POSIX or re::engine::TRE. These modules, which give you posix regular expressions got pulled from CPAN, but you can still find them on backpan. They interpret the /x re option as the regex being an extended re.

        In perldoc POSIX::Regex, jettero writes:
        Yes, I'm aware there's special support for alternate regular expression systems in perl 5.10.x ... let me know when people are done with perl 5.6 and 5.8 and I'll delete this from CPAN. Thanks.

        I'm assuming that is a reference to re::engine::.* packages on CPAN that got pulled. But I've never heard of backpan before this.

        I would like to move forward in a way least likely to cause problems in the future. re::engine::.* seems to provide the cleanest syntax, but until I know better I prefer CPAN to "backpan" packages.

        I don't know why they got pulled from CPAN. Does anyone why that happened? Which would you use: POSIX::Regex from CPAN or re::engine::POSIX from backpan?

Re: Any way to use "POSIX Extended Regular Expressions"?
by Khen1950fx (Canon) on May 21, 2010 at 10:32 UTC
      I ♥ you for the mention.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://841068]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-08-31 00:04 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (294 votes), past polls