aenriqgr
asked on
matching string and get value
Hello
I had one string and a text:
The first is a patron e.g.: 'the X are blue'
and i have a text e.g.: 'in the airport, the plane are blue"
I need match the string with text and get the value
of X. In this case X='plane'.
I had one string and a text:
The first is a patron e.g.: 'the X are blue'
and i have a text e.g.: 'in the airport, the plane are blue"
I need match the string with text and get the value
of X. In this case X='plane'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your answer, your solution is perfect for my problems.
my $object = ($string =~ m/(\S+)\s+are blue/)[0];
print $object;
The (\S+) captures a sequence of non-space characters,
and the (/regexp/)[0] returns the captured value .. this can also be written
$string =~ m/(\S+)\s+are blue/;
my $object = $1;