Do you mean that you only want the first match, or that you only want
the word "chen" when it's not preceeded or followed by other characters?
You can use \b (word boundary) to make sure you got the whole word.

$string =~ /\b(chen)\b/g;

-----Original Message-----
From: chen li [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 03, 2006 3:54 PM
To: beginners@perl.org
Subject: new for regular expression in Perl

Hi all,

Here is my problem:

my $string="chen schen";

I want to use regular expression to find the exact
match in the string. So when I want to match "chen" I
expect "chen" only.
But  use the following line I get both "chen" and
"schen" at the same time.
$string=~/chen/g;

How do I get what I expect?

Thanks,

Li

 


                
__________________________________________ 
Yahoo! DSL - Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to