Very strange... What platform and perl are you on? I'm on RH7.3 perl 5.6.1. And could you try this:
my $a=" foo [ 0 ] = function(a,b,v,t)"; $a=~/\b(\w+)\b\s*?\(/; print "\$` =|$`|\n\$& =|$&|\n\$' =|$'|\n\$1 =|$1|\n"; __END__ My output is this: $` =| foo [ 0 ] = | $& =|function(| $' =|a,b,v,t)| $1 =|function| What is your output? --Brandon P.S. I just tried this on Fedora Core 2 with perl 5.8.3 and got the same output. On Tue, 2005-02-22 at 21:46, Jerry Preston wrote: > Brandon, > > Tried your code and I am still getting "Var_name[ 0 ] =" and not "Func002"; > > Thanks, > > Jerry > > -----Original Message----- > From: Brandon Willis [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 22, 2005 9:30 PM > To: Jerry Preston > Cc: 'Perl Beginners' > Subject: RE: Regex c code > > > As far as I can see you aren't missing anything. > perl -e '$a="foo [ 0 ] = function(1,2,3,4)"; $a=~/(\w+)\(/; print $1' works > great for me. =) > > But you might think about using this: > perl -e '$a=" foo [ 0 ] = function (1,2,3,4)"; $a=~/\b(\w+)\b\s*?\(/; print > $1' > > The zero width assertion \b and the non-greedy space collapse of \s*? handle > a few more simple cases. > > Cheers! > --Brandon > > On Tue, 2005-02-22 at 21:19, Jerry Preston wrote: > > Correction! > > > > I am using /(\w+)\(/ and not /\(/. > > > > Thanks, > > > > Jerry > > > > -----Original Message----- > > From: Jerry Preston [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, February 22, 2005 9:17 PM > > To: 'Perl Beginners' > > Subject: Regex c code > > > > > > Hi! > > > > This seems to so simple, but I do not see what I am doing wrong. > > > > I want to get the function name from a string of c code: > > > > $line = "Func001( 1,2,3,4 )"; > > > > Using $line =~ /\(/; > > Gives $1 = Func001; > > > > Works great, but not on the following > > > > $line = "Var_name[ 0 ] = Func002( d,e,r,t,)"; > > > > Using $line =~ /\(/; > > Gives $1 = Var_name[ 0 ]=; > > > > What am I missing? > > > > Thanks, > > > > Jerry > > > > > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>