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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:54:47+00:00 2026-05-18T19:54:47+00:00

I want to implement a regex matching function in javascript that matches one or

  • 0

I want to implement a regex matching function in javascript that matches one or more keywords in a text. Each keywords has to be found in any order. Keywords are entered by the user.

Here’s where i am at:

\b(smart.*\bwork.*|work.*\bsmart.*)
  • matches "trying to work smarter"
  • but not "trying to work" or "trying to be smart"

The problem with this approach is i have to create different ordered permutations (something like that anyway) of the keyword set.

So the questions are:

  1. If there a simple RegEx-only way? (I.e "\b(smart.*|work.*)<magic:all,anyorder>" what will make sure all keywords are found, and in any order)
  2. If not – can you suggest a javascript implementation of array permutations (so that from [1,2,3] it generates [[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]])

UPDATE

This is intended to be used for searching a set of strings (10-50 strings) on the client side (in browser).

  • 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-18T19:54:47+00:00Added an answer on May 18, 2026 at 7:54 pm

    My friend Juan’s answer will work pretty well unless the user is looking for small words that may appear in larger words. In that case you’ll need to fall back to regular expressions. You can use a hybrid approach that only uses the RE when the string is found. Something like:

    String.prototype.containsAll = function(){
        for (var i=0; i < arguments.length; i++) {
    
            if (this.indexOf( arguments[i] ) > -1 ) {
                // test with regular expressions
                var re = new RegExp('\\b' + escapeRe(arguments[i]) + '\\b')  
                if (!re.test(this)) {
                    return false;
                }
            } else {
                return false
            }
        }
        return true;
    
        function escapeRe(re) {
            return re.replace(/[$.*+?()\[\]\\^]/g, function(chr) {
                return '\\' + chr;
            });
        }
    }
    

    Never tested, especially not the escapeRe bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement this function: Public Function GetFunc(Of TSource, TResult) _ selector As
I want to implement the floating window in the html which it has scroll
I have a configuration file that has variables and value separate by spaces. I
I want to implement like this: namespace PIMP.Web.TestForum.Models { public class ThreadModel : PagedList<T>
I want to implement a properties table in jtable (swing). I want to have
Even after years of programming, I'm ashamed to say that I've never really fully
I am trying to implement a php script which will run on every call
One of the first things I learned as a web developer was to never
Does anyone know where I could find reviews or reports on tasks that people
Yes, I have already asked this question, but the problem is much more specific.

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.