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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:00:05+00:00 2026-05-27T06:00:05+00:00

I want to extract numbers from a string in javascript like following : if

  • 0

I want to extract numbers from a string in javascript like following :

if the string = ‘make1to6’ i would like to extract the numeric character before and after the ‘to’ substring in the entire string. i.e. 1 and 6 are to be extracted

The length of the string is not fixed and can be a max of 10 characters in length.The number can be of max two digits on either side of ‘to’ in the string.

Possible string values :

  • sure1to3
  • ic3to9ltd
  • anna1to6
  • joy1to4val
  • make6to12
  • ext12to36

thinking of something like :

function beforeTo(string) {
    return numeric_value_before_'to'_in_the_string;
}

function afterTo(string) {
    eturn numeric_value_after_'to'_in_the_string;
}

i will be using these returned values for some calculations.

  • 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-27T06:00:06+00:00Added an answer on May 27, 2026 at 6:00 am

    Here’s an example function that will return an array representing the two numbers, or null if there wasn’t a match:

    function extractNumbers(str) {
        var m = /(\d+)to(\d+)/.exec(str);
        return m ? [+m[1], +m[2]] : null;
    }
    

    You can adapt that regular expression to suit your needs, say by making it case-insensitive: /(\d+)to(\d+)/i.exec(str).

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

Sidebar

Related Questions

I want to extract numbers from a string in PHP like following : if
I would like to be able to extract a number from within a string
I want to extract the digits from a string that contains numbers and letters
I want to extract the 73 from this string: wiring_details_1-6-73 The numbers 1, 6
I have the following String and I want to extract the 383-0408 from it,
I want to extract valid(on the basis of format) mobile numbers from a text.
I have a string (char) and I want to extract numbers out of it.
I want to extract two consecutive words starting from each word in a string.
I want to extract an IP address from a string (actually a one-line HTML)
I want to extract version number from string. a string = Tale: The Secrets

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.