Let's say I have a string of text like:
"Hello, your work pin number is 931234. Again, the number is 931234."
How do I parse out the first 6 digit number that I find? (in this case, 931234)
Let's say I have a string of text like:
"Hello, your work pin number is 931234. Again, the number is 931234."
How do I parse out the first 6 digit number that I find? (in this case, 931234)
var msg = "Hello, your work pin number is 931234. Again, the number is 931234";
(msg.match(/\d{6}/) || [false])[0]; // "931234"
if no 6-digit occurence is found then the statement will return false
One way for exactly 6 digits;
var s = "Hello, your work pin number is 931234. Again, the number is 931234."
//start or not a digit, 6 digits, not a digit or end
result = s.match(/(^|[^\d])(\d{6})([^\d]|$)/);
if (result !== null)
alert(result[2]);
var expr = /(\d{6})/;
var digits = expr.match(input)[0];
var text = "Hello, your work pin number is 931234. Again, the number is 931234.".replace(new RegExp("[^0-9]", 'g'), '');
alert(text.substring(0,6));