admin管理员组文章数量:1024615
I have a regular expression that currently matches any non-numeric characters:
var.replace(/[^0-9a-zA-Z ]/,'');
I now need to keep the spaces as well as numbers, but I am having difficulty modifying this.
Any help?
I have a regular expression that currently matches any non-numeric characters:
var.replace(/[^0-9a-zA-Z ]/,'');
I now need to keep the spaces as well as numbers, but I am having difficulty modifying this.
Any help?
Share Improve this question asked Feb 13, 2013 at 16:02 JonJon 3,21411 gold badges41 silver badges60 bronze badges 8- 1 What you have doesn't keep spaces and numbers? – Explosion Pills Commented Feb 13, 2013 at 16:04
- Your regex does not match "any non-numeric characters"; it doesn't match alphabetic characters. – Pointy Commented Feb 13, 2013 at 16:04
- your regex matches none alpha-numeric characters .. not only numeric characters – Hussein Nazzal Commented Feb 13, 2013 at 16:06
- @Rohit Jain - I have been trying things, that is why the regex is almost plete, but I apologise for not being the JavaScript guru you expect me to be. – Jon Commented Feb 13, 2013 at 16:07
- [^0-9\s] this will do it .. this will match every thing that is not a number or space – Hussein Nazzal Commented Feb 13, 2013 at 16:08
1 Answer
Reset to default 6here is a regular expression that will match every thing that is not a number or a space ..
[^0-9\s]
explanation hey regex engine :
1- match every thing .
2- ^
--> that's not
3- 0-9
--> a number
4- \s
--> and a space
I have a regular expression that currently matches any non-numeric characters:
var.replace(/[^0-9a-zA-Z ]/,'');
I now need to keep the spaces as well as numbers, but I am having difficulty modifying this.
Any help?
I have a regular expression that currently matches any non-numeric characters:
var.replace(/[^0-9a-zA-Z ]/,'');
I now need to keep the spaces as well as numbers, but I am having difficulty modifying this.
Any help?
Share Improve this question asked Feb 13, 2013 at 16:02 JonJon 3,21411 gold badges41 silver badges60 bronze badges 8- 1 What you have doesn't keep spaces and numbers? – Explosion Pills Commented Feb 13, 2013 at 16:04
- Your regex does not match "any non-numeric characters"; it doesn't match alphabetic characters. – Pointy Commented Feb 13, 2013 at 16:04
- your regex matches none alpha-numeric characters .. not only numeric characters – Hussein Nazzal Commented Feb 13, 2013 at 16:06
- @Rohit Jain - I have been trying things, that is why the regex is almost plete, but I apologise for not being the JavaScript guru you expect me to be. – Jon Commented Feb 13, 2013 at 16:07
- [^0-9\s] this will do it .. this will match every thing that is not a number or space – Hussein Nazzal Commented Feb 13, 2013 at 16:08
1 Answer
Reset to default 6here is a regular expression that will match every thing that is not a number or a space ..
[^0-9\s]
explanation hey regex engine :
1- match every thing .
2- ^
--> that's not
3- 0-9
--> a number
4- \s
--> and a space
本文标签: regexRemove everything but numbers and spaces in JavaScriptStack Overflow
版权声明:本文标题:regex - Remove everything but numbers and spaces in JavaScript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745611119a2159008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论