in reply to Can qr be un-compiled?

As is pointed out above, Perl regexen and JavaScript regexen are similar but different sublanguages. For simple stuff you may be able to get away with passing JS the stringified version, but a safer alternative would be to use YAPE::Regex to get a parse tree you could walk and translate/downgrade to something suitable for JS.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Can qr be un-compiled?
by massa (Hermit) on Feb 03, 2009 at 15:34 UTC
    sub re_p2js { local @_ = @_; for( @_ ) { 1 while s[^\(\?(\w*)-?\w*:(.*)\)$][/$2/$1] } @_ } print for re_p2js qr/abcde/, qr/(1|2)z$/, qr/^abcd*/ims
    This will extract the outer (?-xims:) -- and it may be enough for your purposes but, as others already posted, it will not compile perl regexen into js regexen.

    UPDATE: changed to respect the flags. The output will be:

    /abcde/ /(1|2)z$/ /^abcd*/msi
    []s, HTH, Massa (κς,πμ,πλ)
      Fails for qr/\//
      Perfect, thanks :)