admin管理员组文章数量:1414628
I am trying to find a way to determine which character in my string does not match the regex, is there a way to do so in Javascript?
I've been using the regex object and i was able to determine whether a string matches the regex but i would like to go step further to determine why a string does not match the regex.
any thoughts?
This was what I currently have ... i am just trying to make sure a string only contains the set of characters found in the following regex ... and i would like to see which character does not match.
Here's my code :
var regexTest = new RegExp("^[0-9a-zA-Z\\!\\040\\@\\s\\#\\$\\%\\&\\*\\(\\)\\_\\+\\:\\\"\\<\\>\\?\\-\\=\\;\\'\\,\\.\\\\]+$",g);
var bValid = regexTest.test(value); //this will check whether the value is valid ...
I've tried using value = value.replace(regexTest,'')
, but was unable to actually filter out the characters.
I am trying to find a way to determine which character in my string does not match the regex, is there a way to do so in Javascript?
I've been using the regex object and i was able to determine whether a string matches the regex but i would like to go step further to determine why a string does not match the regex.
any thoughts?
This was what I currently have ... i am just trying to make sure a string only contains the set of characters found in the following regex ... and i would like to see which character does not match.
Here's my code :
var regexTest = new RegExp("^[0-9a-zA-Z\\!\\040\\@\\s\\#\\$\\%\\&\\*\\(\\)\\_\\+\\:\\\"\\<\\>\\?\\-\\=\\;\\'\\,\\.\\\\]+$",g);
var bValid = regexTest.test(value); //this will check whether the value is valid ...
I've tried using value = value.replace(regexTest,'')
, but was unable to actually filter out the characters.
-
3
I don't think this is really well defined in general. Which character in
"aababb"
doesn't match the regex/^a*b*$/
? Which character in"aaaccc"
doesn't match the regex/^a+b+c+$/
? Which character in""
(ie: the empty string) doesn't match the regex/a+/
? – Laurence Gonsalves Commented Feb 9, 2012 at 17:14
1 Answer
Reset to default 6You could replace all the characters that do match with ''
, leaving only the things that don't match:
'abc123'.replace(/([a-z]+)/g, '')
// "123"
本文标签: Find a way to find characters that doesn39t match the Regex is javascriptStack Overflow
版权声明:本文标题:Find a way to find characters that doesn't match the Regex is javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745177853a2646326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论