For AND searches you need to loop over each keyword. This is the way I would do it...
var allKeywordsExist:Boolean = true; for each(var keyword:String in keywords) { var regexPattern:RegExp = new RegExp(keyword, "i"); allKeywordsExist = allKeywordsExist && regexPattern.test(myBigText); } --- In flexcoders@yahoogroups.com, Baz <li...@...> wrote: > > Here's the actual code, is it possible to replace this with one line of > RegEx: > > var myBigText:String = 'This is sample text to be searched for the existence > of all keywords anywhere in any order'; > var keywords:Array = ['UserProvidedKeyword1', 'UserProvidedKeyword2', > 'UserProvidedKeyword3']; > var allKeywordsExist:Boolean = true; > > for(var i:int = 0; i < keywords.length; i++) { > var myRegEx:regEx = new RegExp('.*' + keyword[i] + '.*', 'i'); > if(!myRegEx.test(myBigText)) { > allKeywordsExist = false; > break; > } > > return allKeywordsExist; > > > > On Thu, Aug 13, 2009 at 6:30 PM, Baz li...@... wrote: > > > Users provide keywords separated by spaces through an input box, and I > > would like to see if they all exist in a certain text. So for example if a > > user provides "flex awesome" or "awesome flex" they should both match the > > phrase "flex is quite awesome". The following regex won't work because it is > > order dependent: .*keyword1.*keyword2.* > > > > Is there a way to tell the regex to search the entire string from the > > beginning for each keyword? > > > > Currently I am looping through each keyword and testing them separately - > > if all tests pass then I return true, but that seems wasteful. > > > > Thanks, > > Baz > > > > > > > > >