NEWBIE: replace punctuation

E

Erich93063

Hi sorry this is probably the easiest answer ever but how do I replace
all punctuation in a variable. I also in the same function want to
replace all spaces with underscores.

THANKS
 
S

scripts.contact

Erich93063 said:
Hi sorry this is probably the easiest answer ever but how do I replace
all punctuation in a variable. I also in the same function want to
replace all spaces with underscores.


try:

variable=variable.replace(/[^\w-]/g,'').replace(/\s/g,'_')
 
E

Erich93063

Erich93063 said:
Hi sorry this is probably the easiest answer ever but how do I replace
all punctuation in a variable. I also in the same function want to
replace all spaces with underscores.

try:

variable=variable.replace(/[^\w-]/g,'').replace(/\s/g,'_')

Thanks.

Ok so I tried that and it did replace the punctuation but the spaces
just got removed instead of being replaced with "_"
 
E

Erich93063

Erich93063 said:
Hi sorry this is probably the easiest answer ever but how do I replace
all punctuation in a variable. I also in the same function want to
replace all spaces with underscores.

variable=variable.replace(/[^\w-]/g,'').replace(/\s/g,'_')

Thanks.

Ok so I tried that and it did replace the punctuation but the spaces
just got removed instead of being replaced with "_"

After messing around with it, this ended up working:

cboModel.value.replace(/ /g,'_').replace(/[^\w-]/g,'')

THANKS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top