我怎样才能只提取以数字结尾的单词?
How can i extract only the words end with number?
我正在从后端获取信息。我需要将其转换为多个单词,并要求存储在数组中。使用 regexp
如何获得?
这是单词:
Enter Room/Area^_^Area 100#_#Enter Grid^_^Grid2#_#Enter Level / Building^_^Building1#_#Enter Drawing^_^Drawing1#_#Enter Spec section^_^Spec2#_#Enter BOQ^_^BOQ1#_#
结果应该是:
["Area 100", "Grid2","Building1", "Drawing1", "Spec2", "BOQ1" ]
所以我想简单地选择以数字结尾的单词。直到特殊字符 ^
.
\b[a-zA-Z0-9 ]+\d+\b
尝试 this.See 演示。
https://regex101.com/r/wZ0iA3/6
var re = /\b[a-zA-Z0-9 ]+\d+\b/gi;
var str = 'Enter Room/Area^_^Area 100#_#Enter Grid^_^Grid2#_#Enter Level / Building^_^Building1#_#Enter Drawing^_^Drawing1#_#Enter Spec section^_^Spec2#_#Enter BOQ^_^BOQ1#_#';
var m;
while ((m = re.exec(str)) != null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
}
我正在从后端获取信息。我需要将其转换为多个单词,并要求存储在数组中。使用 regexp
如何获得?
这是单词:
Enter Room/Area^_^Area 100#_#Enter Grid^_^Grid2#_#Enter Level / Building^_^Building1#_#Enter Drawing^_^Drawing1#_#Enter Spec section^_^Spec2#_#Enter BOQ^_^BOQ1#_#
结果应该是:
["Area 100", "Grid2","Building1", "Drawing1", "Spec2", "BOQ1" ]
所以我想简单地选择以数字结尾的单词。直到特殊字符 ^
.
\b[a-zA-Z0-9 ]+\d+\b
尝试 this.See 演示。
https://regex101.com/r/wZ0iA3/6
var re = /\b[a-zA-Z0-9 ]+\d+\b/gi;
var str = 'Enter Room/Area^_^Area 100#_#Enter Grid^_^Grid2#_#Enter Level / Building^_^Building1#_#Enter Drawing^_^Drawing1#_#Enter Spec section^_^Spec2#_#Enter BOQ^_^BOQ1#_#';
var m;
while ((m = re.exec(str)) != null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
}