in reply to Re: User configurable regex
in thread User configurable regex

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.

Replies are listed 'Best First'.
Re^3: User configurable regex
by Joost (Canon) on Oct 20, 2004 at 11:40 UTC
    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 :)