473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

reg exp to replace non-numeric characters?

Hi,

I'm trying to replace all non-numeric characters with nothing in my
variable. However, this doesn't seem to work ...

var myMixedVar = myMixedVar.replace(/^[0-9]/, "");

Any suggestions what I should have as the reg exp instead?

Thanks, - Dave

Jul 13 '07 #1
3 10360
d d
la***********@zipmail.com wrote:
I'm trying to replace all non-numeric characters with nothing in my
variable. However, this doesn't seem to work ...

var myMixedVar = myMixedVar.replace(/^[0-9]/, "");
I'm no expert on regular expressions, but don't you want the ^ inside
the square brackets, and then a g after the / to make it global.

..replace(/[^0-9]/g,"");

~dd
Jul 13 '07 #2
On Jul 13, 5:40 pm, d d <dd_no_s...@please.netwrote:
laredotorn...@zipmail.com wrote:
I'm trying to replace all non-numeric characters with nothing in my
variable. However, this doesn't seem to work ...
var myMixedVar = myMixedVar.replace(/^[0-9]/, "");

I'm no expert on regular expressions, but don't you want the ^ inside
the square brackets, and then a g after the / to make it global.

.replace(/[^0-9]/g,"");

~dd


^[blah] : b, l, a, or h as the first character in the line
[^blah] : can not match b, l, a, or h
from http://www.javascriptkit.com/jsref/regexp.shtml:
\D Match any non-digit. Equivalent to [^0-9].

so it could also be written

..replace(/\D/g,"");

-Sud.

Jul 14 '07 #3
In comp.lang.javascript message <11**********************@x35g2000prf.go
oglegroups.com>, Fri, 13 Jul 2007 14:25:26, "la***********@zipmail.com"
<la***********@zipmail.composted:
>I'm trying to replace all non-numeric characters with nothing in my
variable. However, this doesn't seem to work ...

var myMixedVar = myMixedVar.replace(/^[0-9]/, "");

Any suggestions what I should have as the reg exp instead?
/\D/g

See references via <URL:http://www.merlyn.demon.co.uk/js-valid.htmor
the link at the one instance of "regexp" in the FAQ.

<FAQENTRYTo that FAQ link should be added one to a similar reference
including newer features; or a new question should be added to introduce
an answer including a set of RegExp references.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
1
by: Luke Dalessandro | last post by:
I have an application where there is a primary XML data file. I'll use the following as an example: <data> <item id="a"> <name>A</name> <price>$10</price> </item> <item id="b">...
12
by: Brian | last post by:
I want to use regxp to check that a form input contains at least 1 non-space charcter. I'd like to only run this if the browser supports it. For DOM stuff, I'd use if (documentGetElementById) {}...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
3
by: DDK | last post by:
I am trying to figure out how to Replace tags such as ... with the correct HTML <b>...</b> tags in C#. The code below works however only if one set of tags are found, if you have more than two...
9
by: Crirus | last post by:
dim pp as string pp="{X=356, Y=256}{X=356, Y=311.2285}{X=311.2285, Y=356}{X=256, Y=356}{X=200.7715, Y=356}{X=156, Y=311.2285}{X=156, Y=256}{X=156, Y=200.7715}{X=200.7715, Y=156}{X=256,...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
3
by: Brad | last post by:
I see the use of Javascript replace all over the web. What are all the character sequences? (sorry I am a bit of a newbie at this). i.value.replace(/+/g, ''); I understand that /g is global...
1
by: Michael Yanowitz | last post by:
Hello: I am hoping someone knows if there is an easier way to do this or someone already implemented something that does this, rather than reinventing the wheel: I have been using the...
5
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.