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!

Non Case Sensitive Replacement 1

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am trying to replace occurrences of certain words in text with hyperlinks. The replacement works ok if I ensure the text to match is the same case as the pattern.
The problem is that the text could be Downloads, DOWNLOADS, DownLoads etc.

I can match the presence of the required word by forcing upper case but how do I do the replacement?
Code:
if(uc($styl_res[4])=~ m/$TITLE_NAMES[$kx]/){

According to my docs, the 'i' operator should work but no replacement is made.
Code:
$styl_res[4]=~ s/$TITLE_NAMES[$x]/$LINK/i;
Could someone please tell me what I am doing wrong?


Keith
 
You've got $TITLE_NAMES[$kx] in the first instance and $TITLE_NAMES[$x] in the second. Should the 'k' be there?
 
It should be ok, but may be you wanna add the "g" flag because this way you will replace only the first occurence.

Corwin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top