pattern match

  • Thread starter Venkatesh can....can...
  • Start date
V

Venkatesh can....can...

$var="{' venkat'}->{'no'}->{'yes'}";
i want to get the "yes" token;
if i use
$var=~/\{'( .* )\}$/
i get venkat'}->{'no'}->{'yes
how to get the "yes" token...
 
G

Gunnar Hjalmarsson

Venkatesh said:
$var="{' venkat'}->{'no'}->{'yes'}";
i want to get the "yes" token;
if i use
$var=~/\{'( .* )\}$/
i get venkat'}->{'no'}->{'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 =~ /.+{'(.+)'}$/;
 
V

venkatesh.naughty

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.


One way:

     $var =~ /.+{'(.+)'}$/;

@gunnar

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

Gunnar Hjalmarsson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top