gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:10:38 24 4
gpt4 key购买 nike

如果在字符串中找到子字符串并且该子字符串将以其他字符串结尾,我需要返回 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com