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

Find and Replace All Forward Slashes Only

Status
Not open for further replies.

fox12

Programmer
Jan 18, 2005
62
US
How can I cleanly replace all forward slashes "/" with "/ " in a page with javascript? I tried the following code:
document.body.innerHTML = document.body.innerHTML.replace(regstr, "/ ");
But that seems to replace all occurrences of the "/" in the closing tags "</" of the HTML source code.

How to negate "</" but find all "/"?

Thanks.
 
change your regstr to: "([^<]/)" and your repl string to "$1/&nbsp;"

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
tracy ur code has typos:

TheStr=TheStr.replace(/([^<])\//g,"$1")

Known is handfull, Unknown is worldfull
 
Tracy,
Your solution half works. Here is the exact effect I want to achieve:
From: value=/export/home/fox12/customers/orders
To: value=/ export/ home/ fox12/ customers/ orders

Here is the code I used your way:
document.body.innerHTML.replace(/([^<]\/)/g,'$1/&nbsp;');
I get the following:
value=// export// home// fox12// customers// orders
 
oh god, i misread:
document.body.innerHTML.replace(/\//g,'/&nbsp;');


Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top