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
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery, dropdown 4 37
Form submit issue 11 54
Location of Javascript on HTML page 3 25
javascript email link with image 2 19
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now