Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,其值如下:
share__43 share__153 share share_section
如何获得 43 或 153 之类的整数值?
尝试这个
var regex = new RegExp(/([0-9]+)/g); var test = "share__43 share__153 share share_section"; var match = regex.exec(test); alert('Found: ' + match[1]);
小提琴
示例,当前使用单个字符串
var regex = /\d+/; var str = "share__43"; alert (str.match(regex ));
演示