Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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_Regex_Typescript_Google Cloud Functions - Fatal编程技术网

Regex 获取两个字符之间的数字-Typescript

Regex 获取两个字符之间的数字-Typescript,regex,typescript,google-cloud-functions,Regex,Typescript,Google Cloud Functions,我对Typescript还不熟悉,并试图在我的谷歌云功能中创建一个webhook 我有一个字符串:C1234567890A460450P10TS1596575969702 我想使用正则表达式从该字符串中提取数字1234567890。 第一个字符C是固定不变的,数字后的字符A是可变的,可以是任何其他字母 匹配数字的正则表达式是?有两个问题,您从未使用parseInt将返回的字符串解析为数字,这是否回答了您的问题?或者:@AhmedAbdelhameed他们帮不上忙。我已经更新了OP.let reg

我对Typescript还不熟悉,并试图在我的谷歌云功能中创建一个webhook

我有一个字符串:C1234567890A460450P10TS1596575969702

我想使用正则表达式从该字符串中提取数字1234567890。 第一个字符C是固定不变的,数字后的字符A是可变的,可以是任何其他字母


匹配数字的正则表达式是?有两个问题,您从未使用parseInt将返回的字符串解析为数字,这是否回答了您的问题?或者:@AhmedAbdelhameed他们帮不上忙。我已经更新了OP.let regxp=/?您的响应为空,因为当您不使用/../format:let regxp=new RegExp'时,您的RegExp中的反斜杠需要转义。只需做一些小的更改,我就可以将其用于我的案例。谢谢
const string = request.body.string;

let regxp = new RegExp('(?<=C)(\d{10})(?=\w)');
const number = regxp.exec(string);

response.send(number);
const string: string = request.body.string;


const matches = s.match(/^C\d{10}/);
let number: number;
if(matches !== null) {
    number = parseInt(matches[0].slice(1));
} else {
    res.status(400).end(); // Assuming this is express
    return;
}

res.send(number); // 1234567890