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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:10:40+00:00 2026-06-05T06:10:40+00:00

I need a regex expression that performs a contains function on a input/type=hidden field’s

  • 0

I need a regex expression that performs a “contains” function on a input/type=hidden field’s value. This hidden field stores unique values in a comma delimited string.

Here’s a scenario.
The value: “mix” needs to be added to the hidden field. It will only be added if it does not exist as a comma delimited value.

With my limited knowlege of regex, I can’t prevent the search from returning all ocurrences of the “mix” value. For example if: hiddenField.val = ‘mixer, mixon, mixx’, the regex always returns true, because the all three words contain the “mix” characters.

Thanks in advance for the help

  • 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-05T06:10:41+00:00Added an answer on June 5, 2026 at 6:10 am

    You can use \b metacharacter to set word boundaries:

    var word = "mix";
    new RegExp("\\b" + word + "\\b").test(hidden.value);
    

    DEMO: http://jsfiddle.net/ztYff/


    UPDATE. In order to protect our regular expression of possible problems when using variable instead of hardcoding (see comments below), we need to escape special characters in word variable. One possible solution is to use the following method:

    RegExp.escape = function(text) {
        return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    }
    

    DEMO: http://jsfiddle.net/ztYff/1/


    UPDATE 2. Following @Porco’s answer we can combine regular expressions and string splitting to get another universal solution:

    hidden.value.split(/\s*,\s*/).indexOf(word) != -1;
    

    DEMO: http://jsfiddle.net/ztYff/2/

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

Sidebar

Related Questions

This sounds simple but my regex knowledge is limited. I need an expression to
I need a regular expression that matches currency values similar to here: Regex for
I often use regex expression validators that are also a required field. Which leads
Here's a quickie for your RegEx wizards. I need a regular expression that will
what Regex Expression do we need to use in this scenario Iam looking to
I'm in need of a regular expression that checks if the input is exactly
I'm trying to write a regex expression that will take this phrase [[32, 120],
I need a Regex expression for PHP that finds exactly 8 characters in a
I'm a regex newbie and need a single expression that: matches the an and
I need a regular expression that matches APA format references. I currently have this:

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.