in reply to User configurable regex

Can you give an example? I can't really see what the problem would be. ie, this works:

my $re = <STDIN>; chomp ($re); my $line = <STDIN>; chomp ($line); print "$line =~ /$re/\n"; if ( $line =~ /$re/ ) { print "match"; } else { print "no match"; }
with input
a\d3 a23
gives
a23 =~ /a\d3/ match

Replies are listed 'Best First'.
Re^2: User configurable regex
by MiggyMan (Sexton) on Oct 20, 2004 at 11:32 UTC
    Well for a start im looking at substitutions not matches.

    Now if I pass the substitution from a variable I have to go and escape a whole bunch of thing OR make the user do it when they set the regex (which doesnt make me happy at all).

    for example

    ---------------------- #!/usr/bin/perl $user=".admin.ecc"; $uregex="~s/^\\.(\.*)?\\.\.*/\$1/"; #$user =~ s/^\.(.*)?\..*/$1/; $regstring="\$user=$uregex"; print "$regstring\n"; eval($regstring); print "User: $user\n"; ----------------------


    The regex to process my username is s/^\.(.*)?\..*/$1/ but in order to get it working with eval it needs to be changed to this s/^\\.(\.*)?\\.\.*/\$1/ which is not the most usefull thing in the world so what im looking for is some means to parse a regex string, if it comes down to it i'll use a whole bunch of regex for it but id rather not if i can help it.
      Why would your users have to type the double quotes?
      #!/usr/bin/perl -w use strict; my $substitution = '$line =~ '.<DATA>; my $line = "abcdef"; eval $substitution; print $line; __DATA__ s/abc(\w+)f/xxx$1x/;
      output:
      xxxdex
      Update: what I mean is; the problem you're describing only occurs in string literals (and it could already be a lot less annoying if you used single quotes). this interpolation does not occur in strings per se.
        You know i did try this earlier and im sure i did it right but to no avail however i've just done so again and it's working :)

        I'll go hide in the corner :)

        Just so you know the user would *never* type the regex out as such. they'll ultimatley be entering it via a gui interface and sending it off to a server to store in a config file, the regex is used in a print system i've been developing to re-format the usernames into more readable forms and it's used by the input filter :)