Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > NEWBIE: replace punctuation

Reply
Thread Tools

NEWBIE: replace punctuation

 
 
Erich93063
Guest
Posts: n/a
 
      05-04-2007
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

 
Reply With Quote
 
 
 
 
scripts.contact
Guest
Posts: n/a
 
      05-04-2007

Erich93063 wrote:
> 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,'_')

 
Reply With Quote
 
 
 
 
Erich93063
Guest
Posts: n/a
 
      05-04-2007
On May 4, 12:48 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
> Erich93063 wrote:
> > 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 "_"

 
Reply With Quote
 
Erich93063
Guest
Posts: n/a
 
      05-04-2007
On May 4, 12:59 pm, Erich93063 <erich93...@gmail.com> wrote:
> On May 4, 12:48 pm, "scripts.contact" <scripts.cont...@gmail.com>
> wrote:
>
> > Erich93063 wrote:
> > > 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 "_"


After messing around with it, this ended up working:

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

THANKS

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stripping out punctuation marks dew ASP .Net 1 02-07-2006 12:06 AM
Combine 2 Columns to one with punctuation DBLWizard ASP .Net 10 04-02-2005 12:07 AM
Remove punctuation from String? dfhLASST Java 4 11-11-2004 03:57 PM
Re: Regular expression for punctuation Chris R. Timmons ASP .Net 0 07-10-2003 03:57 AM
Regular expression for punctuation Chris Leffer ASP .Net 0 07-09-2003 02:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57