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

Replacing Text 2

Status
Not open for further replies.

progolf069

Programmer
Jun 13, 2001
37
0
0
US
Greetings,

I have a quick, appears to be easy, question about replacing text in a string. I am trying to display on a web page the registered trademark, trademark, and copyright symbols out of a Postgresql database. These data items are being representated in the data like this:

Trademark: (tm) or (TM)
Copyright: (c) or (C)
Registred Trademark: (r) or (R)

An example record would be something like this:
American Tourister(r) Forester(tm) II Collection - Ultravalet(r) Garment.

Anywhere there is a (r) or a (tm) in the above statement, should be replaced with the following text:

Code:
Trademark: <SMALL><SUP>TM</SUP></SMALL>
Copyright: & #169
Registred Trademark: & #174

-+-+-+-+-+-+-+-+-+

I have tried using a simple replace feature as followed, but I am am getting these reults

Code:
$item1 = 'American Tourister(r) Forester(tm) II Collection - Ultravalet(r) Garment';

$item1 =~ s/(tm)/<SMALL><SUP>TM</SUP></SMALL>/;
$item1 =~ s/(r)/& #174/;
$item1 =~ s/(c)/& #169/;

print &quot;$item1&quot;;

Result: Ame®i©an Tourister(r) Forester(tm) II Collection - Ultravalet(r) Garment

If anybody can assist me in figuring out how to code this, I would be very appreciative. Thanks for any replys that you may give.

God Bless You,
Ian Wickline
 
Code:
$item1 =~ s/\(tm\)/<SMALL><SUP>TM</SUP></SMALL>/g;
$item1 =~ s/\(r\)/& #174/g;
$item1 =~ s/\(c\)/& #169/g;

You look for true parenthesis in the string (not the regular expression grouping parenthesis) so you have to protect '(' and ')' with '\'.
You want to change all occurences so add the global 'g' modifier at the end.
 
You will need to escape the '/' in the end tag or use a different s/// delimiter.
Code:
$item1 =~ s/\(tm\)/<SMALL><SUP>TM<\/SUP><\/SMALL>/g;
# Or
$item1 =~ s!\(tm\)!<SMALL><SUP>TM</SUP></SMALL>!g;

jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top