Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex typescript使用typescript中的正则表达式提取子字符串_Regex_Typescript - Fatal编程技术网

Regex typescript使用typescript中的正则表达式提取子字符串

Regex typescript使用typescript中的正则表达式提取子字符串,regex,typescript,Regex,Typescript,我正在尝试在TypeScript中使用正则表达式来 检查给定字符串是否与表达式匹配 提取子字符串 这是我试图匹配的两个字符串 总订单 例如:Total Order order1,我应该能够从正则表达式中提取order1 另一个我想要匹配的字符串是。我一直试图这样做,但没有任何成功,我遇到了以下问题,但没有成功 ,但这和我想做的不同 项目顺序,也可以有空格 例:项目订单1。我应该能够再次从中提取order1。您可以使用Regexp Match: const str = 'Items Order o

我正在尝试在TypeScript中使用正则表达式来

检查给定字符串是否与表达式匹配 提取子字符串 这是我试图匹配的两个字符串 总订单 例如:Total Order order1,我应该能够从正则表达式中提取order1

另一个我想要匹配的字符串是。我一直试图这样做,但没有任何成功,我遇到了以下问题,但没有成功 ,但这和我想做的不同

项目顺序,也可以有空格
例:项目订单1。我应该能够再次从中提取order1。

您可以使用Regexp Match:

const str = 'Items Order order1';
const matches = str.match(/Items\sOrder\s(\w+)/);
if (matches) {
    console.log(matches[1]); // ordem1    
}

如果已填充matches变量,则在捕获的数组组的第二个位置将有一个有效内容。

您有问题吗?