Link to home
Start Free TrialLog in
Avatar of aenriqgr
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'.

Avatar of perldork
perldork

my $string = "The things are blue";

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;
ASKER CERTIFIED SOLUTION
Avatar of PC_User321
PC_User321

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aenriqgr

ASKER

Thanks for your answer, your solution is perfect for my problems.