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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression help

Status
Not open for further replies.

Zippeh

Programmer
Sep 24, 2002
56
GB
Hey!

I want to write a small regular expression to replace "&" with "&" in URLs. Some of the URLs already contain the "&" so I want to skip these ones.

So I need a regular expression that will ignore any "&" followed by "amp;". Any idea how I'd get about this?
 
Is it likely that the ampersand to denote and, will always be followed by a space?
Code:
$str =~ s/& /&/g

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Not when the & is contained within the querystring part of an URL :)
 
fair enough ...:~/
mental note to self, read whole post ;-)
 
Do you need the other XML escapes ", ', <, > as well? In which case, make sure you do the & substitution first - you get really strange results otherwise [smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Yeah I got a big function that changes them all, first thing it does it do & -> & :D
 
If it's that good post it ;-)

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Haha I would, but it's in VBScript (flame away!)

Just posted in here cos it's where I thought the regexp experts would be residing ;)
 
Mum, Dad, there's something you need to know about me. I'm not like the other kids my age. I'm a VBScript programmer... [smile]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top