How to get substring from string javascript

Posted on 2009-04-01
Last Modified: 2012-05-06
Hi, I have this string:

How to get 65789??

Open in new window

Question by:Saroj13
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 17

Expert Comment

ID: 24042506
Please refer:
JavaScript substring() Method
JavaScript - Strings
Javascript: substr() v.s. substring() « Rudimentary Art of ...
LVL 12

Expert Comment

ID: 24042526
var str = "";
var regEx = /([0-9]+)/;
var match = regEx.exec(str)[0];

Expert Comment

ID: 24042531
i.e. like this:

var str = '';
            var reg = new RegExp('(.*)Stories\/([0-9]+)\?(.*)','i');
            var val = str.replace(reg,'$2');

Open in new window

LVL 11

Accepted Solution

petiex earned 500 total points
ID: 24042694
Or, you could just use string functions
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    <script type="text/javascript">
        function testFunction(str){
         alert(getStringBetweenLastSlashAndQuestionMark(str)+" should be 65789");
        function getStringBetweenLastSlashAndQuestionMark(str){
            return str.substring(str.lastIndexOf("/")+1,str.indexOf("?"));
<a href="#" onclick="javascript:testFunction(''); return false;">click</a>

Open in new window


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question