actionscript 3 - AS3 RegEx: Match Keywords -


i trying match of few keywords in string using regex in as3. following example.

var sourcestring = "no, working on it. there might delay."; var keywords = ["no", "delay"]; 

i need check if of keywords present in source string. keywords , source strings dynamic. need take source string input user , search keywords in string. can there 1 generic regex pattern achieve this?

you can construct new regexp object , use match against source string.

for example:

var sourcestring = "no, working on it. there might delay."; var keywords = ["no", "delay"];  var expression:regexp = new regexp(keywords.join("|"), "ig");  if (expression.test(sourcestring)) {     // match found } else {     // no match found } 

(untested code.)


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -