RegEx question

Matt Graham danceswithcrows at usa.net
Thu Sep 17 08:57:19 MST 2009


From: Paul Mooring <drpppr242 at gmail.com>
> This is probably a really obvious question but how can I match
> everything up to a character not including that character with regex?
> For example:
> person at email.tld => person
> me at here.com => me

#!/usr/bin/perl -w
$a="person\@mail.com";
$a=~m/^(.*)\@/;
$b=$1;
print "a= $a\n";
print "b= $b\n";

You may have to modify the regex and the structures for non-Perl
languages since @ is a special char in Perl and may not be in others.
The regex here matches everything from the beginning of the string
up to the first @, not including the @, and puts it in $1 or \1
(first backreference).

But if this was all I wanted, I might use a substr instead of a
regex, since regexes are a bit more complex than what you said
you wanted.  (Don't use a .50 to shoot a chipmunk, etcetera....)

-- 
Matt G / Dances With Crows
The Crow202 Blog:  http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see




More information about the PLUG-discuss mailing list