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

  • Home
  • SEARCH
  • 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 509235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:59:23+00:00 2026-05-13T06:59:23+00:00

I’ve already looked at this , which was helpful to a point. Here’s the

  • 0

I’ve already looked at this, which was helpful to a point.

Here’s the problem. I have a list of users propagated into an element via user click; something like this:

<div id="box">
    joe-user
    page-joe-user
    someone-else
    page-someone-else
</div>

On click, I want to make sure that the user has not already been clicked into the div. So, I’m doing something like:

if ( ! $('#box').html().match(rcpt) )
{
   update_div();
}
else
{
   alert(rcpt+' already exists.');
}

However, with existing lack of interpolation that javascript has for regular expressions, is causing my alert to trigger in the use-case where page-joe-user is selected and then the user selects joe-user, which are clearly not exactly the same.

In Perl I would do something like:

if ( $rcpt =~ /^\Qrcpt\E/ )
{
    # code
}

All I want to do is change my match() to be:

if ( ! $('#box').html().match(/^rcpt/) )
{
    # code
}

if ( ! $('#box').html().match(rcpt) ) seemed a little promising but it, too, fails. Using new RegExp() also does not work using concatenation of complex RE syntax within the function IE $('#box').html().match(new RegExp('^'+rcpt)). I also tried $('#box').html().match('/^'+rcpt'/'). I can only imagine that I’m missing something. I’m pretty new to javascript.

I don’t seem to be able to find anything that really addresses such a use-case, here on this site.

TIA

  • 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-13T06:59:23+00:00Added an answer on May 13, 2026 at 6:59 am

    The match function only works on strings, not jQuery objects.

    The best way to do this is to put each username into a separate HTML tag.

    For example:

    <ul id="users">
        <li>joe-user</li>
        <li>page-joe-user</li>
        <li>someone-else</li>
        <li>page-someone-else</li>
    </ul>
    

    You can then write the following:

    if($('#users li').is(function () { return $(this).text() === rcpt; }))
    

    If you want to do it your way, you should call text() to get the string inside the element. ($('#box').text().match(...))


    EDIT: The best way to do this using your HTML would be to split the string.

    For example:

    var userExists = false;
    var users = $('#box').text().split(/\r?\n/);
    
    for(var i = 0; i < users.length; i++) {   //IE doesn't have indexOf
        if (users[i] == rcpt) {
            userExists = true;
            break;
        }
    }
    if (userExists) {
        //Do something
    }
    

    This has the added benefit of not being vulnerable to regex-injection.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.