正则表达式:匹配以任意数字结尾的字符串

Regular expression : match a string that end with any number

本文关键字:数字 结尾 字符串 任意 正则表达式      更新时间:2023-09-26

我想得到一个正则表达式,它给我一个以任意数字结尾的字符串。

示例:

输入字符串:[test-1,test-2,test-200,test-34dd,test-sdfsd,test-4]

输出(匹配字符串)应该像:

[test-1,test-2,test-200,test-4]

匹配后面跟着破折号的任何单词和任何数字:

^('w+)-('d+)$

您可以尝试以下regex来匹配以字符串test开头、以数字结尾的字符串

^test-.*?'d$

演示

由于每行需要多个匹配项,因此必须有/g选项。

此外,您需要单词边界iso字符串边界。

请检查以下解决方案:

'b'w+-'d+'b

播放,并查看解释:

http://regex101.com/r/sO3dZ0/1