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 <[email protected]> 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
>
>
>
>