Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl : How to match a parenthesis inside a regexp?

Tags:

regex

perl

I'm trying to extract some fields from a fixed format data, which looks like this:

G1 = DFF(G2)

Say $_ has the above line, and I want to get G1 and G2 after matching it with a suitable reg exp. I'm using this :

if (/(w+)\s*=\s*DFF\((w+)\)/)
{     
    print "$1, $2";
}

But this isn't printing what I want (prints nothing, which means my pattern is wrong). Can anyone show me what I'm doing wrong (pls be patient, this is my first perl program !!)

like image 398
TCSGrad Avatar asked Dec 09 '25 10:12

TCSGrad


1 Answers

if (/(\w+)\s*=\s*DFF\((\w+)\)/)

It's not the parens that are incorrect, it's the word match \w that needs an escape.

like image 53
Mat Avatar answered Dec 12 '25 00:12

Mat