javascript - 正则表达式查找字符串是否有子字符串并以另一个子字符串结尾

标签 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 来检查字符串的结尾。

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

但我想要一个正则表达式来找到这两件事。

最佳答案

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

/US.*\.properties$/

RegEx Demo

关于javascript - 正则表达式查找字符串是否有子字符串并以另一个子字符串结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32080319/

相关文章:

javascript - 如何在 Ember 中查找包含关联 promise 的记录?

javascript - React 组件动画

php - 从 Google Places API 获取地址信息

html - 为什么我的本地 html 链接会转到父文件夹而不是 .html?

c# - 使用 html5 将 byte[] 显示为 pdf

javascript - 如何使用nodejs/javascript实现地理编码响应?

javascript - 如何设置struts <html :select> value in java class

javascript - 滚动到移动设备上的元素时触发事件

javascript - 如何将一个html文件包含在另一个html文件中?最好、最有效的方法是什么?

internet-explorer - IE 兼容模式错误