Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Regex matching a string beginning with "root: " but not containing another string

by jryan (Vicar)
on Sep 09, 2004 at 20:08 UTC ( #389865=note: print w/ replies, xml ) Need Help??


in reply to Re: Regex matching a string beginning with "root: " but not containing another string
in thread Regex matching a string beginning with "root: " but not containing another string

Here's a different way to do it. IMHO, the regex it produces will be much easier and make much more sense.

use strict; my $email = "myself\@domain.of-my.own"; my $string = "root: myself\@domain.of-my.own"; my $re = inv_str_seq($email); $string =~ /^root: $re/ and print 1; sub inv_str_seq { my($string) = @_; my @c = map { quotemeta($_) } split '', $string; my $re = "\n [^$c[0]] \n"; $re .= " | " . join('',@c[0..$_-1]) . " [^$c[$_]]\n" for (1 .. $#c); $re = qr/$re/x; return qr/$re+ (?:[^$c[0]]|$)/x; }

Update: Moved the quotemeta up.


Comment on Re^2: Regex matching a string beginning with "root: " but not containing another string
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-07-28 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (251 votes), past polls