Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  45] [ 7]  / answers: 1 / hits: 130331  / 15 Years ago, mon, march 8, 2010, 12:00:00

How can I extract 456 from xxx_456 where xxx is of indefinite length?


More From » string

 Answers
69

var str = xxx_456;
var str_sub = str.substr(str.lastIndexOf(_)+1);


If it is not always three digits at the end (and seperated by an underscore). If the end delimiter is not always an underscore, then you could use regex:




var pat = /([0-9]{1,})$/;
var m = str.match(pat);

[#97400] Thursday, March 4, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
victorr

Total Points: 193
Total Questions: 86
Total Answers: 105

Location: Pitcairn Islands
Member since Thu, Jun 24, 2021
3 Years ago
victorr questions
Fri, Nov 13, 20, 00:00, 4 Years ago
Sat, Jul 25, 20, 00:00, 4 Years ago
Thu, Jun 11, 20, 00:00, 4 Years ago
;