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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:15:10+00:00 2026-05-22T16:15:10+00:00

I have the following URL: http://example.com/product/1/something/another-thing Although it can also be: http://test.example.com/product/1/something/another-thing or http://completelydifferentdomain.tdl/product/1/something/another-thing

  • 0

I have the following URL:

http://example.com/product/1/something/another-thing

Although it can also be:

http://test.example.com/product/1/something/another-thing

or

http://completelydifferentdomain.tdl/product/1/something/another-thing

And I want to get the number 1 (id) from the URL using Javascript.

The only thing that would always be the same is /product. But I have some other pages where there is also /product in the url just not at the start of the path.

What would the regex look like?

  • 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-22T16:15:11+00:00Added an answer on May 22, 2026 at 4:15 pm
    1. Use window.location.pathname to
      retrieve the current path (excluding
      TLD).

    2. Use the JavaScript string
      match method.

    3. Use the regex /^\/product\/(\d+)/ to find a path which starts with /product/, then one or more digits (add i right at the end to support case insensitivity).

    4. Come up with something like this:

      var res = window.location.pathname.match(/^\/product\/(\d+)/);
      if (res.length == 2) {
          // use res[1] to get the id.
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a URL which can be any of the following formats: http://example.com https://example.com
I have something like the following: final String url = http://example.com; final HttpClient httpClient
Assume I have the following URL stored in variable called content : http://www.example.com/watch?v=4444444&feature=related Problem:
I'm trying to do the following: I have the url: http://www.example.com/9999 and I want
I have an existing journal website with the following url structure http://example.com/dbtable_id/ (eg. http://example.com/89348/)
I have the following url: http://mywebsite.com/somepage.php?product=343&type=4 I want the user to be able to
I have the following script in my javascript... $.ajax({ type: 'POST', url: 'http://www.example.com/ajax', data:
I have the following url which will always have a color variable attached: http://www.example.com/?new=yes&color=red&shape=square
I have the following url: http://example.com/folder/index.php?module=centrale&DIO0=1 I need this page to be availeble with
I have the following line in my IsapiRewrite.ini file: RewriteRule ^/test-url.asp$ http://www.google.co.uk/ [R=301,L] But

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.