Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl regex to POSIX

by quester (Vicar)
on Feb 06, 2007 at 07:39 UTC ( [id://598492]=note: print w/replies, xml ) Need Help??


in reply to Perl regex to POSIX

You might want to elaborate a little more on the actual regexes that you want to convert, and what program you will be feeding those converted regexes into. I think the reason no one has posted anything yet is that the most general case of a "perl regex" includes all manner of horrors that would be very difficult to translate properly, but are also not heavily used.

Offhand, it looks like anything that appears in the perlre documentation before the topic (?=pattern) should be tolerable to convert to the POSIX regex format in, for example, http://www.tin.org/bin/man.cgi?section=7&topic=regex. The expressions described after that point in perlre are likely to be difficult. On the other hand, all of them except the zero-width lookahead and lookbehind assertions are marked "experimental", so it's not unlikely that your particular RE's don't use any of those features.

Replies are listed 'Best First'.
Re^2: Perl regex to POSIX
by Sifmole (Chaplain) on Feb 06, 2007 at 14:07 UTC
    I appreciate the input.

    Unfortunately, what I said about covers the details; but I will try again.

    There is an application which allows users to input regular expressions which are saved and used later for different operations. The input regular expressions are validated by passing them through the qr() method and accepted if they do not throw an error. This has to this point worked fine as the later processing was being performed in Perl code.

    I have a requirement that involves moving that same processing into a database model ( Postgres ) and support the existing regular expressions which users have already saved. I thought to convert the existing expressions to POSIX format because Postgres supports that.

    Thanks in advance for any help.

      That's actually a much better problem description because you've a) nailed down the why behind what you're attempting to do which can dispel any lingering hints of X-Y problems, and b) given a more concrete target (convert Perl regexen into POSIX regexen as understood by Postgres).

      You might look into building a convertor on top of YAPE::Regex. It would parse an existing regex and then walk it emitting a Postgres regex equivalent (or throwing an error if it encounters something like (?{}) which doesn't have an analogue).

      Update: D'oh! Forgot that Pg can embed Perl; that'd be a much better route if you can swing it than translating. Go with the suggestion below if you can; parse and convert as a last resort.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://598492]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-20 04:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found