Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Character replace using jquery Reply To: Character replace using jquery

#158362
CrocoDillon
Participant

It’s late and I’m sleepy so not sure if this is the best solution, but this RegEx should work /([^:]\/)\//g, use it like:

s = s.replace(/([^:]\/)\//g, '$1');

Basically it replaces every // with / as long as it’s not preceded by a colon (like in http://).

Not jQuery, but I don’t think jQuery got any helper functions for this anyway. Curious about use cases though.