简体   繁体   English

匹配以数字结尾的常量词的正则表达式是什么

[英]What will be the Regular expression for matching a constant word ending with number

The string's I want to match are like -我想匹配的字符串就像 -

'RANDOM1', 'RANDOM2', 'RANDOM78'

Here the word RANDOM is constant always ending with a number.这里随机这个词是常数,总是以数字结尾。 Any help would be appreciated.任何帮助,将不胜感激。

您需要从行首 ( ^ ) 和之后的一个或多个字符 ( + ) 开始匹配单词 RANDOM

you got downvoted for not showing any effort你因为没有表现出任何努力而被低估

RANDOM[0-9]+随机[0-9]+

is a regex that will trap what you look for.是一个正则表达式,它将捕获您要查找的内容。

You can try this:你可以试试这个:

 var str='RANDOM1'; if(/^RANDOM\\d+$/gi.test(str)) console.log('true'); else console.log('false');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM