Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Any way to use "POSIX Extended Regular Expressions"?

by Lightknight (Beadle)
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"?

Replies are listed 'Best First'.
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.


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.

      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?

      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".
      Thanks for your reply, but as I said in my original post: "MySQL doesn't use Perl compatible regular expressions"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://841068]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-02-19 14:57 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (266 votes). Check out past polls.