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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:10:49+00:00 2026-05-21T12:10:49+00:00

I am writing a bit of javascript that grabs user ID’s. It works, but

  • 0

I am writing a bit of javascript that grabs user ID’s. It works, but the problem is the actual regular expression is being included in the results.

My code it:

var regex = /profile\.php\?id=(\d*)/g;
var matches = source.match(regex);

And it returns:

profile.php?id=1111,1111,profile.php?id=2222,2222,profile.php?id=33333,33333,

All I want is the user ID’s. Am I doing something wrong?

  • 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-21T12:10:50+00:00Added an answer on May 21, 2026 at 12:10 pm

    string.match with the g flag only returns strings that match the full regular expression. What you want is capturing groups, you’ll need to use RegExp.exec

    Something like this:

    var text="lots of stuff with something in here a few times so that something comes back multiple times when searching for something.";
    
    var regex=new RegExp("some(thing)","g");
    
    var result=null;
    
    while(result=regex.exec(text)){
        document.write(result[1]);
    }
    

    You should read up on capturing groups in regex to understand why this works. The first group is always the full match then each of the capturing groups in order.

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

Sidebar

Related Questions

I'm writing a bit of javascript and need to choose between SVG or VML
I'm writing my first bit of jQuery, and I'm having a problem with jQuery.get()
I am writing a small application with Qt 4.6 (64-bit Arch Linux, though that
I'm writing a quite complex JavaScript application that has an MVC architecture that I'm
I'm writing a quiz program using PHP and a bit of Javascript. The questions
Here is function that i am writing on 64 bit linux machine. void myfunc(unsigned
When you're writing a program that consists of a small bit of main logic
I am writing a Rails 3 generator, but things get a bit complicated so
I'm writing a bit of JavaScript code which should select a random item from
I'm writing a bolt-on bit of javascript which is intended to capture information when

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.