js regexp problem

Posted by Alexander on Stack Overflow See other posts from Stack Overflow or by Alexander
Published on 2011-03-12T21:49:26Z Indexed on 2011/03/13 0:10 UTC
Read the original article Hit count: 248

Filed under:
|

I have a searching system that splits the keyword into chunks and searches for it in a string like this:

var regexp_school = new RegExp("(?=.*" + split_keywords[0] + ")(?=.*" + split_keywords[1] + ")(?=.*" + split_keywords[2] + ").*", "i");

I would like to modify this so that so that I would only search for it in the beginning of the words.

For example if the string is:

"Bbe be eb ebb beb"

And the keyword is: "be eb"

Then I want only these to hit "be ebb eb"

In other words I want to combine the above regexp with this one:

var regexp_school = new RegExp("^" + split_keywords[0], "i");

But I'm not sure how the syntax would look like.

I'm also using the split fuction to split the keywords, but I dont want to set a length since I dont know how many words there are in the keyword string.

split_keywords = school_keyword.split(" ", 3);

If I leave the 3 out, will it have dynamic lenght or just lenght of 1? I tried doing a

 alert(split_keywords.lenght);

But didnt get a desired response

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex