What you want is a negative lookahead

$iter =~ s/\b$varS(?!\.)/St./gi;

That says to find any occurrence of $varS that is preceeded by a word
boundry (so you don't replace things like worst) and is NOT followed by a .

Tanton

-----Original Message-----
From: Miretsky, Anya
To: '[EMAIL PROTECTED]'
Sent: 11/15/2001 10:37 AM
Subject: Regulare Expressions/ Substitution Question

I am trying to replace all occurences of the word St with St. without
generating St.. in the incorrect substitutions of St. 

The code I have been playing with is something like:

$item = "35 Main St." (it could also be "35 Main St" in which case I
want
the substitution to happen)

$varS = "st";
$item =~ s/\b$varS(^.|\W)\b/St./gi;

This doesn't work because Perl is expecting a character after the $varS
string, but I don't know how to specify to substitute for the contents
of
$varS except when it ends with a period.

Can anyone help?

Thanks in advance.
 

Anya Miretsky
Computer Technology Dept.
Brooklyn Botanic Garden
1000 Washington Avenue
Brooklyn, NY  11225

(718)623-7265
[EMAIL PROTECTED] 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to