开发者

need an regular expressions

Please help I need an regular expressions that can get any other string except specific one, for example I set the specific one to be "abc", then any other string like "bac", "cbaad", etc can be accept, but if "abc", no.

hope that make sense, than开发者_Go百科k you.


If your specific string is a single string i.e. on abc then you can do it using simple if condition,

if(myStr != "abc")
{
    // check myStr with regular expression of required pattern
}


As other answers have pointed out there is no need for regex in your simple example, but here is a regex that will do the job just in case you dumbed down your example too much and you actually have a need for something like this.

^(?!abc$).*

And if abc can't occur anywhere in the string:

^(?!.*abc).*


If "abc" should not occur anywhere in the string,

var str = "bcabcd"; 
var noNoStr = "abc";
var pattern = new RegExp(noNoStr);
var result = !pattern.test(str);


if you want to exclude "abc" only why not do simple comparision... x == 'abc'

i.e

if( str == 'abc')
{
...
}else{
...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜