简体   繁体   English

javascript 匹配以特定单词结尾的字符串的正则表达式[重复]

[英]javascript regex to match a string ends with particular word [duplicate]

I have two strings我有两个字符串
"track/bugfix merged to 'master'"
"track/bugfix merged to 'track/clonemaster'"

I want regex to match string ends with 'master' only can anyone help me on this?我希望正则表达式匹配以'master'结尾的字符串,谁能帮我解决这个问题?

To get the end of a string, use the $ anchor, this signifies the end of a line.要获取字符串的结尾,请使用$锚点,这表示一行的结尾。

So, the regular expression that you are looking for is as follows:因此,您正在寻找的正则表达式如下:

/'master'$/gi

 const matches = [ "track/bugfix merged to 'master'", "track/bugfix merged to 'track/clonemaster'" ].map(testString =>..testString.match(/'master'$/gi)) console.log(matches)

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

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