我想获取字符串中的一项,
主要字符串是:This is an inactive AAA product. It will be replaced by replacement AAAA/BBBB number ABX16059636/903213712 during quoting
我想获取ABX16059636/903213712,,有什么方法可以用Regex来实现吗?
请分享一些建议。
发布于 2017-05-30 13:41:37
我去了https://regex101.com/r/ARkGkz/1
这就是结果:
const regex = /number ([^ ]+) /;
const str = `This is an inactive AAA product. It will be replaced by
replacement AAAA/BBBB number ABX16059636/903213712 during quoting`;
let m;
if ((m = regex.exec(str)) !== null) {
let match = m[1];
console.log(`Found match: ${match}`);
}正则表达式本身可以理解为:
首先匹配空格括号包含我们想要的部分,表示“capture
[^ ] characters"
+ 一定要使用https://regex101.com/r/ARkGkz/1,并尝试这样做。
https://stackoverflow.com/questions/44253998
复制相似问题