edward edward - 2 months ago 8
Javascript Question

I need to match a specific part of text and get the following numbers out using jquery

So I have a a div which contains mixed text (symbols, numbers, text etc) and I want to grab the numbers after matching a particular part.

For example:

Within the text is a part which says 'StartTime=' and this is followed by a timestamp which is what I need to get.

"EndTime=Fri, 23 Sep 2016 01:37:26 UTC client area:v2.1.2
operation = successful Time=9910 ms StartTime=1474594636638
client prod name EndTime=Fri, 23 Sep 2016 01:37:26 UTC client
area:v2.1.2 operation = successful Time=9910 ms"


out of the text above, I need to get this number out '1474594636638'

Answer

You could either use a regex

var numb = text.match(/StartTime=(.*?)\s/)[1];

or just split

var numb = text.split('StartTime=').pop().split(' ').shift();
Comments