Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4043732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:09:51+00:00 2026-05-20T13:09:51+00:00

I have a searching system that splits the keyword into chunks and searches for

  • 0

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 function to split the keywords, but I don’t want to set a length since I don’t 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 length or just length of 1? I tried doing a

 alert(split_keywords.lenght);

But didn’t get a desired response

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:09:52+00:00Added an answer on May 20, 2026 at 1:09 pm

    You should use the special word boundary character \b to match the beginning of a word. To create the expression for an arbitrary number of keywords, you can generate it in a loop.

    var regex = '';
    
    for(var i = split_keywords.length;i--; ) {
        // two slashes are needed to insert `\` literally
        regex += "(?=.*\\b" + split_keywords[i] + ")";
    }
    
    var regexp_school = new RegExp(regex, "i");
    

    I’m not sure about performance, but you can also consider to use indexOf to test whether a substring is contained in a string.

    Update:

    If \b does not work for you (because of other “special” characters), and all your words are separated by a white space, you can use

    "(?=.*\\s" + split_keywords[i] + ")"
    

    or

    "(?=.* " + split_keywords[i] + ")"
    

    But for this to work you have to prepend the text you are searching in with a white space:

    " " + textYouSearchIn
    

    or you are write a more complex expression:

    "(?=(^|.*\\s)" + split_keywords[i] + ")"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a a few queries in our system that use LIKE '%'+@SomeCriteria+'%' to
I have a web-based documentation searching/viewing system that I'm developing for a client. Part
I'm new to rails, and trying to develop a system that will have several
Have been searching how to convert a dictionary to a string. But the results
I have been searching for a command that will return files from the current
I have tried searching over the internet about this problem but not able to
I have been searching for a solution to this and so far found nothing
I have been searching for information on this for about 30mins now and got
I have this function I am using to decrypt values that works fine on
I have a small java program that searches the contents of all *.txt files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.