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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:47:49+00:00 2026-05-31T23:47:49+00:00

I am having a little trouble with regular expression. I want to match a

  • 0

I am having a little trouble with regular expression.

I want to match a regular expression in a sentence.

Example :

John has two candy ::123::

and i am using this code to look for it:

var getid = x$('div').html().match(/::([^:]+)::/g);

To get the 123 our of the sentence.

So what’s my problem here?
I kept on getting an undefined value for getid var.

  • 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-31T23:47:49+00:00Added an answer on May 31, 2026 at 11:47 pm

    The problem is the g flag. You don’t use it with String#match. Remove it and it works fine (live copy | source):

    var getid = x$('div').html().match(/::([^:]+)::/);
    if (getid) {
        display("Found: " + getid[1]);
    }
    else {
        display("Not found");
    }
    

    If you want to find all of the matches in the text, use RegExp#exec and a loop (and the g flag) (live copy | source):

    var rex = /::([^:]+)::/g;
    var str = x$('div').html();
    var getid;
    while (getid = rex.exec(str)) {
        display("Found: " + getid[1]);
    }
    

    (For greater clarity, you might use

    while ((getid = rex.exec(str)) != null) {
    

    …since having an assignment in a test looks like a = instead of == typo; but it comes to the same thing other than readability.)


    Re your comment below asking about x$(this), it should make any difference. Here are the above examples reworked to use x$(this):

    • One match: Example | source
    • Loop: Example | source
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a little trouble constructing the regular expression using java. The constraint is,
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I am having a little trouble using addoperationwithblock in Cocoa. Let's say I have
I'm having a little trouble using jQuery in Rails. I'd like to call the
I'm having a little trouble about using multiple Left Joins in a query. Some
I'm having a little trouble with pthreads. Basically, I want to catch a SIGINT
Having a little trouble on this one. I need a way using Jquery/JS to
I am having a little trouble working with static methods in C++ Example .h:
i'm having a little trouble with an elseif MySQL query i'm using to search
I'm having a little trouble organizing my error messages for two interacting classes. One

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.