Search for a or b in a string - Javascript -
how can search if string contains or b or c in javascript?
i need test if string contains "is" or "test" or "string".
var string = "this test string search"; var result = string.indexof("is"||"test"||"string");
but doesn't work
it better use regular expression here:
if ( /is|test|string/.test(string) ) { ... }
however, if want search words, i'd suggest use special character \b
.
ref: https://developer.mozilla.org/en-us/docs/javascript/guide/regular_expressions
Comments
Post a Comment