Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrong with this reg expression?

Status
Not open for further replies.

dimitad

Programmer
Joined
Sep 16, 2006
Messages
10
Location
US
Hi all,

I cant figure out why this regular expression generates an error:

s/([0-9a-zA-Z])/"<a href=some.php?id=".process($1)."></a>"/ei )

"process($1)" is a function call but I have the "e" attribute at the end so that its evaluated correctly. The error from this is: Bareword found where operator expected at file.pl

Also if I remove the part after process($1) - it works?!?

Thanks!
 
The forward slash in </a> closes your regular expression. You have two options.

a) escape the forward slash by putting a backslash before it:
Code:
s/([0-9a-zA-Z])/"<a href=some.php?id=".process($1)."><\/a>"/ei

b) use a different delimiter for your regexp:
Code:
s!([0-9a-zA-Z])!"<a href=some.php?id=".process($1)."></a>"!ei
s{([0-9a-zA-Z])}{"<a href=some.php?id=".process($1)."></a>"}ei
s,([0-9a-zA-Z]),"<a href=some.php?id=".process($1)."></a>",ei
 
Thanks a bunch - that saved me some debugging!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top