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

String Replace Ever Second Character 2

Status
Not open for further replies.

MarkZK

Technical User
Jul 13, 2006
202
GB
Hi All,

I'm trying to think of a way to write a function to remove every second "`" character from a string, I have nothing coded right now as I'm already stuck as to actually go about it.

for example, I have a string like..

Code:
str="`14`red¬file`55`green¬folder`22`lime¬folder`11`gray¬file";

(the string length isn't static and can have various amounts of inputs, but the pattern will always be the same)

I'd like the string from the function to return

Code:
"`14red¬file`55green¬folder`22lime¬folder`11gray¬file";

as you can see every second ` character is removed.

any ideas would be great thanks.
 
[tt]str="`14`red¬file`55`green¬folder`22`lime¬folder`11`gray¬file";
var rx=/(`.*?)(`)/g;
var str2=str.replace(rx,"$1");
alert(str+"\n"+str2);
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top