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 8225709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:30:22+00:00 2026-06-07T15:30:22+00:00

I am working on regex for searching hotel list. There are names like testing

  • 0

I am working on regex for searching hotel list. There are names like “testing hotel plaza”, “testing2 newhotel plaza”, “plaza hotel”….

Basically my requirement is if user type plaza then all the hotels should populate which contains “Plaza”… but if user types “aza” no result should populate. In short in given string I need to find is there any word that start with user entered string and if yes, then display the result.

Here is a code that I am stuck and is not working.

var regex = new RegExp("/\b"+searchString, "gi");
if (mainString.match(regex))
{
    return true;
}

This is working but it is finding all occurrences even if it is a middle character or at any position which I do not want.

var regex = new RegExp(searchString , "gi");
if (mainString.match(regex))
{
    return true;
}
  • 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-06-07T15:30:23+00:00Added an answer on June 7, 2026 at 3:30 pm

    When invoking the RegExp constructor like this, the regex is not enclosed in slashes (/.../), but you have a leading forward slash in your string. Also, escape sequence backslashes need to be escaped themselves, so what you should be using is

    var regex = new RegExp("\\b"+searchString, "gi");
    

    EDIT:

    Yes, since \b is defined relative to [A-Za-z0-9_], this is indeed problematic when it comes to non-ASCII chars. You could probably solve it using more or less complicated lookarounds, but a much easier solution which would most likely do the trick here is to say that searchString should be found either at the beginning or after a whitespace character:

    var regex = new RegExp("(?:^|\\s)"+searchString, "gi");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an app that needs to accept a RegEx from the user,
I'd like to have a substitute or print style command with a regex working
I have this regex working but now need to allow numbers without the decimal
My understanding of regex and working with strings in php is poor at best
Alright, this is driving me nuts because my regex is working on Rubular, but
I'm working with the following RegEx function in Excel 2010 and am getting the
I am working on string maniplations using regex. Source: string value = @/webdav/MyPublication/Building%20Blocks/folder0/folder1/content_1.xml; output
Possible Duplicate: PHP REGEX: Get domain from URL I am working on a project
! I am working with the replace method of VBA Regex and am wondering
I am currently working with the following pseudo code block to fix a regex

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.