Reputation:
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'
Upvotes: 0
Views: 29
Reputation: 328
You can get the substring of the part you need:
var string = "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";
var startTime = string.substring(string.indexOf('StartTime='), string.indexOf(' client prod name')).replace('StartTime=', '');
console.log(startTime);
Upvotes: 0
Reputation: 318312
You could either use a regex
var numb = text.match(/StartTime=(.*?)\s/)[1];
or just split
var numb = text.split('StartTime=').pop().split(' ').shift();
Upvotes: 1