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!

have problem in variable matching and substitution

Status
Not open for further replies.

yuenlok

Technical User
Nov 20, 2002
18
0
0
CA
Hi,

I need to replace strings in a URL when the date key value for example "Nov18" matches variable $DATE, the original strings look like:
newsletter.mydomain/;kw=frNov18tracking
newsletter.mydomain/;kw=engNov18tracking

what I need is something like:
mydomain.dart/nlsample

Here is the what I used but it didn't work out: $DATE=Nov18
s/newsletter\.mydomain\/\;kw=[eng|fr]$DATEtracking/mydomain\.dart\/nlsample/g;

With this substitution I got :
mydomain.dart/nlsamplengNov18tracking
mydomain.dart/nlsamplerNov18tracking

so [eng|fr]Nov18tracking became [ng|r]Nov18tracking and was append to the target string. Can anybody tell me what's wrong with my substitution? Thanks very much!

 
will this take care of it?

Code:
$_ = "newsletter.mydomain/;kw=frNov18tracking";

$DATE="Nov18";

print "$_\n";

s/^.*$DATE.*$/mydomain\.dart\/nlsample/g;

print "$_\n";
 
oops.. forgot the eng/fr

s/^.*(eng|fr)$DATE.*$/mydomain\.dart\/nlsample/g;

parens will look for eng or fr only if grouped together -
brackets will treat each character inside individually.
[eng|fr] = e or n or g or |(actual pipe character)or f or r

the ^ and $ anchor the beginning and end, so it will replace the whole string.
 
Hi Dummy33,

I replaced [eng|fr] with (eng|fr) and use parens to identify $DATE:

s/newsletter\.mydomain\/\;kw=(eng|fr)($DATE)tracking/mydomain\.dart\/nlsample/g;

Now I get what I need. Thanks very much.

btw, I can't use ^.* and .*$ to replace the whole string because the other part of the URL is important to me ;-)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top