简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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