Thanks Chris and others for the information. Chris, I have another question: I have a file containing multiple lines and it looks like this:
(line 1).....chen..... (line 2).............. (line 3) chen......... If I read the whole file at once and change it into a string I have no problem using regular expression to find out the word "chen". But it looks like a little bit unnatural for me because it changes the file's format. Is it possible to do the match without change the file format? One way I think is to use a loop to read the file line by line and do the match for each line. I wonder if this is the best way to get the job done. Once again thank you very much, Li --- Chris Charley <[EMAIL PROTECTED]> wrote: > > ----- Original Message ----- > From: "chen li" <[EMAIL PROTECTED]> > > > > 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? > > Hi Chen > > You can get the results by adding a \b before and > after your reg expression. > \b is a boundary between a word and a non-word > character. (A word character > is a-z, A-Z, 0-9, or underscore, _).So, for your > example, schen wouldn't > match then because the 's' preceding 'c' is a word > character and so the \b > wouldn't be true. But, it would match chen because > the (non) character > (beginning of the string) preceding the 'c' would > make \b true. > > $string=~/\bchen\b/g; > > MATCH > "chen " > "#chen" > "here is a chen and another chen" > "chen's" (the apostrophy is a non-word char) > > NO MATCH > "schen" > "chens" > > Chris > > > > -- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > <http://learn.perl.org/> > <http://learn.perl.org/first-response> > > > __________________________________________ 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>