Reputation: 117
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, thank you.
Upvotes: 0
Views: 61
Reputation: 208455
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).*
Upvotes: 3
Reputation: 465
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);
Upvotes: 2
Reputation: 17653
if you want to exclude "abc" only why not do simple comparision... x == 'abc'
i.e
if( str == 'abc')
{
...
}else{
...
}
Upvotes: 0
Reputation: 8117
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
}
Upvotes: 5