正则表达式,用于查找字符串是否具有子字符串并以另一个子字符串结尾

时间:2015-08-18 18:43:02

标签: javascript jquery html regex

如果在字符串中找到子字符串并且以其他字符串结尾,我需要返回true。

表示如果我有类似下面的字符串,那么regx应该返回true,因为它在字符串中有大写US,并且以.properties结尾

/sap/m/messagebundle_en_US.properties

我的字符串如下

EG: -

/sap/m/messagebundle_en_US.properties -- true
/sap/m/messagebundle_US_en.properties -- true
/sap/m/messagebundle_us_en.properties -- false(not upper case US)

我在regx中很穷。我用Google搜索并成功找到了一个将检查字符串结尾的regx。

/.*.properties$/.test(".properties"); 

但我想要一个regx来找到这两件事。

1 个答案:

答案 0 :(得分:1)

您可以使用此正则表达式:

/US.*\.properties$/

RegEx Demo