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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -