CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Problem extracting an expression

 



jkepler
New User

Jul 22, 2014, 2:01 AM

Post #1 of 4 (2021 views)
Problem extracting an expression Can't Post

Hi,

I'm trying to extract an expression from a line. Here's what I'm doing:

my $exp = $line =~ m/[FAR PASCAL|FAR PASCAL_CONV]\ (.*)\(/gi;

with $1 I get the expression I want, but also the sring PASCAL !
The $line exp is of the type:

FAR PASCAL what_i_want(etc...)
or
FAR PASCAL_CONV what_i_want(etc...)

What am I doing wrong...? Frown

Kind regards,

jkepler


BillKSmith
Veteran

Jul 22, 2014, 7:40 AM

Post #2 of 4 (2014 views)
Re: [jkepler] Problem extracting an expression [In reply to] Can't Post

Your biggest mistake is to use '[..]' when you mean non-capturing parenthesis '(?:...)'. The /g flag is not required for your example. $exp does not contain what you expect because if forces scalar context.


Code
use strict; 
use warnings;
#my $line = 'FAR PASCAL_CONV what_i_want(etc...)';
my $line = 'FAR PASCAL what_i_want(etc...)';
my ($exp) =
$line =~ m/
FAR\sPASCAl # Required
(?:_CONV)? # Optional - Do not capture
\s # Required
(.*) # Capture Desired Output
\( # Required
/xi;

print $exp, "\n";

Good Luck,
Bill


hwnd
User

Jul 22, 2014, 8:13 AM

Post #3 of 4 (2012 views)
Re: [jkepler] Problem extracting an expression [In reply to] Can't Post


Code
my ($exp) = $line =~ m/PASCAL\S*\s*(.*)\(/i;



jkepler
New User

Jul 22, 2014, 12:12 PM

Post #4 of 4 (2004 views)
Re: [recruiter] Problem extracting an expression [In reply to] Can't Post

Thank you very much :)

JKepler

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives