Re: RegEx question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Matt Graham
Date:  
To: Main PLUG discussion list
Subject: Re: RegEx question
From: Paul Mooring <>
> 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
> => 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


---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change your mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss