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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:28:47+00:00 2026-05-21T00:28:47+00:00

alert($(this)[0]); returns a url, eg. http://localhost/www/anotherdir/go.php?id=12aaa I wish to place the 12 and the

  • 0

alert($(this)[0]); returns a url, eg. http://localhost/www/anotherdir/go.php?id=12aaa

I wish to place the “12” and the “aaa” into separate vars (quoted vals could be anything, but will always be a number followed by three alpha).

Using the regex /\?* returns id=12aaa in a regex editor, but…

This does not generate an alert() box – nothing happens at all:

x = $(this)[0].match(/\?*/);
alert(x);

This also does not do anything:

x = $(this)[0].match(/\?*/);
alert(x[0]); 
  • 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-21T00:28:48+00:00Added an answer on May 21, 2026 at 12:28 am

    Try this:

    var x = $(this)[0].match(/[^\?]*$/);
    alert(x[0]);
    

    Pretending that $(this)[0] returns “/my/fun/path?query1=a&query2=b
    Note that x will be the array ["query1=a&query2=b"]

    If you, for instance, wanted to get each query parameter as an index in an array you could do this:

    var params = $(this)[0].match(/[^\?]*$/)[0].split('&');
    

    Which will give you:

    ["query1=a", "query2=b"]
    

    Editing to break-down the regex for you:

    • The [] is a character class, and can only ever match one single character no matter how much contents it has.
    • [a-z] for instance, will match any single lower-case alphabetic character.
    • The ^ (caret) at the beginning of the character class is a not-identifier. Indicating that this character class has an opposite effect – it will match any single character that does NOT match the rest of the contents. This position (first character in a character class) is the only time that the caret indicates ‘not’. In other contexts it has a different meaning (For instance, at the beginning of your regex the ^ will indicate that the beginning of the string must start there).
    • Thus, our character class [^\?] indicates that we will match any single character that is not a question mark
    • The asterisk always means “zero or more of the preceding statement”, so when you were trying to just use * to mean “anything here” what you were actually doing was duplicating the \? zero or more times – stating to the interpreter “I want a question mark zero or more times”. Your alert(x[0]) should have output an empty dialog, more on that later
    • In our case the asterisk is checking for any non-question mark, zero or more times.
    • The $ at the end of the reg-ex states “End of string” which means… of course, that the end of the string must be at that point.

    Therefore we know the regex will not collect the question mark from your url because then it would not be able to hit the end of the string while still collection multiple non-question marks. The * is always greedy unless otherwise specified, so it will get as many characters as possible.

    Your alert(x[0]) should have output an empty alert (I tested it, and it did for me) because the .match() method matches the first thing it can, since /\?*/ matches virtually every single string possible it must have stopped after seeing the first character and saying “oh there’s a match here!”

    Hopefully this was helpful for your understanding 🙂 Regexes can be confusing when you start out with them but I absolutely love ’em. So powerful.

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

Sidebar

Related Questions

I have a URL like below : http://localhost:1692/fa/Help.aspx#Help the code below returns that :
This code var offset = $('#snapwrap_inner').offset(); alert(offset.left) in FF returns 0px but in Opera
I have a very basic AJAX function in JQuery: $.ajax({ url: http://www.google.com, dataType: html,
I am trying to access token from http://localhost:8090/appp/appp/getToken it returns me string with Content-Type:application/json
Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));
i have this code $(function() { $('#ans_vote a span').click(function(){alert('working');return false;});}); and this html <div
$(a.close).click(function() { var id = $(this).attr(id); alert(id); $(this).parents(div.venue:first).fadeOut(Fast); return false; }); Any ideas why
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
I am getting a wrong output when i alert this, it shows '01' <input
Code: ​var a = function() { this.message = hello; this.shout = function(){ alert(this.message); //

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.