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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:03:45+00:00 2026-05-25T14:03:45+00:00

I want to run a script that extracts an integer from the URL hash

  • 0

I want to run a script that extracts an integer from the URL hash (#), or zero if no integer is found.

The URLs could be any of these formats:

  1. http://www.example.com/book/#page-cover
  2. http://www.example.com/book/#page-1
  3. http://www.example.com/book/#page-12
  4. http://www.example.com/book/#page-123

The above examples would return:

  1. 0
  2. 1
  3. 12
  4. 123

I’m running jQuery and looking for the cleanest way of doing this in either pure Javascript or jQuery.

Thanks in advance.

  • 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-25T14:03:46+00:00Added an answer on May 25, 2026 at 2:03 pm

    You could do it in one line:

    var integer = window.location.hash.match(/\d+/) | 0;
    
    • This will match the first one or more digits in the hash.
    • then bitwise OR the result with 0. Javascript bit operations are on 32-bit signed integer (except >>>)
    • return the result of the match as an integer, or if match is undefined, return zero
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run a php script from the command line that is always
I have a python script that i want to run from the command line
I have a Iron Python script that I want to run and then have
My $SHELL is tcsh. I want to run a C shell script that will
I want to run a python script from within another. By within I mean
I have a zsh script that I want to run such that it also
I have created a Python script that I want to run daily via a
i guys i have a problem, i want to run a haskell script that
I want to run 15 instances of a script that pipelines 5 scripts together,
I wrote a Ruby script that I want to run in the background repeatedly

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.