我想在字符串中获取一个项目
主字符串是:这是一个非活动的AAA产品。在引用期间将替换为替代AAAA / BBBB编号ABX16059636 / 903213712
我只想获取“903213712”,有没有办法用Regex实现这个?
尝试使用以下正则表达式,它给出了16059636/903213712 ==>斜线后我只期待903213712。
var string = "This is an inactive AAA product. It will be replaced by replacement AAAA/BBBB number ABX16059636/903213712 during quoting"
var result = string.match(/\d+/g)
//var resVal = result.toString().split("/");
alert(result);
答案 0 :(得分:8)
你差不多完成\/
缺少=> /\/(\d+)/g
解释
\/
与/
\d+
匹配一个数字(等于[0-9])。有关详细信息,请参阅演示正则表达式
var string = "This is an inactive AAA product. It will be replaced by replacement AAAA/BBBB number ABX16059636/903213712 during quoting"
var result =/\/(\d+)/g.exec(string)
console.log(result[1]);