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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:58:49+00:00 2026-06-12T13:58:49+00:00

Using javascript regular expressions, how do you match one character while ignoring any other

  • 0

Using javascript regular expressions, how do you match one character while ignoring any other characters that also match?

Example 1: I want to match $, but not $$ or $$$.
Example 2: I want to match $$, but not $$$.

A typical string that is being tested is, “$ $$ $$$ asian italian”

From a user experience perspective, the user selects, or deselects, a checkbox whose value matches tags found in in a list of items. All the tags must be matched (checked) for the item to show.

    function filterResults(){

// Make an array of the checked inputs
var aInputs = $('.listings-inputs input:checked').toArray();
// alert(aInputs);
// Turn that array into a new array made from each items value.
var aValues = $.map(aInputs, function(i){
    // alert($(i).val());
    return $(i).val();
});
// alert(aValues);
// Create new variable, set the value to the joined array set to lower case.
// Use this variable as the string to test
var sValues = aValues.join(' ').toLowerCase();
// alert(sValues);

// sValues = sValues.replace(/\$/ig,'\\$');
// alert(sValues);

// this examines each the '.tags' of each item
$('.listings .tags').each(function(){
    var sTags = $(this).text();
    // alert(sTags);
    sSplitTags = sTags.split(' \267 '); // JavaScript uses octal encoding for special characters
    // alert(sSplitTags);
    // sSplitTags = sTags.split(' \u00B7 '); // This also works

    var show = true;

    $.each(sSplitTags, function(i,tag){

        if(tag.charAt(0) == '$'){
            // alert(tag);
            // alert('It begins with a $');
            // You have to escape special characters for the RegEx
            tag = tag.replace(/\$/ig,'\\$');
            // alert(tag);
        }           

        tag = '\\b' + tag + '\\b';

        var re = new RegExp(tag,'i');

        if(!(re.test(sValues))){
            alert(tag);
            show = false;
            alert('no match');
            return false;
        }
        else{
            alert(tag);
            show = true;
            alert('match');
        }
    });

    if(show == false){
        $(this).parent().hide();
    }
    else{
        $(this).parent().show();
    }

});

// call the swizzleRows function in the listings.js
swizzleList();
}

Thanks in advance!

  • 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-12T13:58:51+00:00Added an answer on June 12, 2026 at 1:58 pm
    \bx\b
    

    Explanation: Matches x between two word boundaries (for more on word boundaries, look at this tutorial). \b includes the start or end of the string.

    I’m taking advantage of the space delimiting in your question. If that is not there, then you will need a more complex expression like (^x$|^x[^x]|[^x]x[^x]|[^x]x$) to match different positions possibly at the start and/or end of the string. This would limit it to single character matching, whereas the first pattern matches entire tokens.

    The alternative is just to tokenize the string (split it at spaces) and construct an object from the tokens which you can just look up to see if a given string matched one of the tokens. This should be much faster per-lookup than regex.

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

Sidebar

Related Questions

I would like a JavaScript regular expression that will match time using the 24
How to capture the following pattern using JavaScript regular expressions? I would like to
I need to add markup to some text using JavaScript regular expressions. In Python
Using JavaScript I'm trying to split a paragraph into it's sentences using regular expressions.
I want to extract abc from images/abc.png using Javascript Regular experssion in one line.
I am have completed javascript validation of a form using Regular Expressions and am
How to match the following string using regular expression in JavaScript? Has a total
Is it possible, using Javascript and either jQuery or regular expressions, to group multiple
Do there exist comprehensive regular expressions that, when applied to JavaScript source code, will
I'm having trouble converting DMS to DD in javascript using regular expressions. I took

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.