d-_-b
d-_-b

Reputation: 23161

Add exception to regex

I'm using this code I stumbled upon to 'clean up' urls with jquery:

.replace(/[^\w ]+/g,'') // and
.replace(/ +/g,'-')

The first one removes non alpha-numeric characters, while the second turns spaces into a dash

My question is: Is there a way to exclude a character, in my situation, # , from this first .replace() ?

Thank you.

Upvotes: 1

Views: 3015

Answers (1)

zerkms
zerkms

Reputation: 254886

.replace(/[^\w#\/ ]+/g,'') // and

Upvotes: 3

Related Questions