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

Re: Tidying and simplifying a regular expression

by ikegami (Pope)
on Dec 12, 2017 at 17:21 UTC ( #1205350=note: print w/replies, xml ) Need Help??

in reply to Tidying and simplifying a regular expression

It's relatively easy to spot that it's just a (?:..........)

It could just as easily be two `(?:...)` back to back. Therefore, tidying this up requires a complete regexp parser. And since Perl regex patterns can contain arbitrary Perl code, you also need a complete Perl parser if the pattern includes `(?{...})` or `(??{...})`.

So no, it's immensely hard to spot that it's just `(?:...)`.

It might be easier to address the problem at the source, which means replacing

my $augmented_pattern = "$re"; ... my $re = qr/$augmented_pattern/;
my ($pattern, $mods) = re::regexp_pattern($re); ... my $re = eval("qr/\$pattern/$mods") or die $@;

Replies are listed 'Best First'.
Re^2: Tidying and simplifying a regular expression
by Dallaylaen (Hermit) on Dec 13, 2017 at 07:13 UTC

    You are right, "easy to spot" was a bit of exaggeration. However, most of the time (like 90%) the augmented pattern is really not going to contain much more than or's, concatenations, multipliers, and capture groups. So one could get away with much less than a full-blown Perl parser.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1205350]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2018-03-21 17:54 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (270 votes). Check out past polls.