Click here to get back home

pattern match

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
pattern match Venkatesh can....can... 03-20-2008
---> Re: pattern match Gunnar Hjalmars...03-20-2008
  ---> Re: pattern match venkatesh.naughty03-20-2008
    ---> Re: pattern match Gunnar Hjalmars...03-20-2008
    `--> Re: pattern match Tad J McClellan03-20-2008
Posted by Venkatesh can....can... on March 20, 2008, 1:29 am
Please log in for more thread options
$var="{' venkat'}->->";
i want to get the "yes" token;
if i use
$var=~/\{'( .* )\}$/
i get venkat'}->->{'yes
how to get the "yes" token...

Posted by Gunnar Hjalmarsson on March 20, 2008, 2:02 am
Please log in for more thread options
Venkatesh can....can... wrote:
> $var="{' venkat'}->->";
> i want to get the "yes" token;
> if i use
> $var=~/\{'( .* )\}$/
> i get venkat'}->->{'yes

No you don't. You get nothing, because that regex does not match.
However, with the /x modifier it matches and assigns the string you
mention to $1.

> how to get the "yes" token...

One way:

$var =~ /.+$/;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by venkatesh.naughty on March 20, 2008, 2:18 am
Please log in for more thread options
> Venkatesh can....can... wrote:
> > $var=3D"{' venkat'}->->";
> > i want to get the "yes" token;
> > if i use
> > $var=3D~/\{'( .* )\}$/
> > i get venkat'}->->{'yes
>
> No you don't. You get nothing, because that regex does not match.
> However, with the /x modifier it matches and assigns the string you
> mention to $1.
>
> > how to get the "yes" token...
>
> One way:
>
> =A0 =A0 =A0$var =3D~ /.+$/;
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl

@gunnar

thanks it works but how?
the first .+ is greedy know? it 'll match up to the end right?

Posted by Gunnar Hjalmarsson on March 20, 2008, 6:13 am
Please log in for more thread options
venkatesh.naughty@gmail.com wrote:
>> Venkatesh can....can... wrote:
>>>
>>> $var="{' venkat'}->->";
>>> i want to get the "yes" token;
>>> if i use
>>> $var=~/\{'( .* )\}$/
>>> i get venkat'}->->{'yes
>>
>> No you don't. You get nothing, because that regex does not match.
>> However, with the /x modifier it matches and assigns the string you
>> mention to $1.
>>
>>> how to get the "yes" token...
>>
>> One way:
>>
>> $var =~ /.+$/;
>
> thanks it works but how?
> the first .+ is greedy know?

Yes.

> it 'll match up to the end right?

No, it matches one or more characters as long as it can without
preventing the whole regex from matching; in this case up to and
including the second arrow.

Remember that greediness never affects whether a regex matches or not.
It just may affect _how_ the regex matches.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Frank Seitz on March 20, 2008, 6:42 am
Please log in for more thread options
Gunnar Hjalmarsson wrote:
> venkatesh.naughty@gmail.com wrote:
>>
>>the first .+ is greedy know?
>
> Yes.
>
>>it 'll match up to the end right?
>
> No, it matches one or more characters as long as it can without
> preventing the whole regex from matching; in this case up to and
> including the second arrow.

Internally .+ matches the whole string at first.
Then, the regex-engine backtracks until it achieves an
overall match (or not).

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Similar ThreadsPosted
pattern match July 26, 2005, 3:42 pm
match pattern "not" June 26, 2008, 9:20 am
pattern match with newline July 27, 2004, 9:07 pm
Use of uninitialized value in pattern match (m//) October 19, 2005, 7:58 am
use of uninitialised value in pattern match (m//) May 17, 2006, 12:21 am
Use of initialized value in pattern match May 18, 2006, 2:10 pm
Problem with pattern match March 8, 2007, 10:07 am
match string by re using some pattern July 25, 2007, 9:44 am
Match repeating pattern September 8, 2007, 2:41 am
newbie pattern match question :-) January 14, 2005, 2:49 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap