RegexpGarden










- Garden Text Representation
12345
let garden = [ "Rose", "Primrose", "Rosemary", "Christmas Rose", "Echinacea 'Sunrise'"];- Code Editor
- Log
123456
for (const plant of garden) {if (plant.match(//i) {water(plant);}}Lesson task •
Water plants ending with "rose"
End of string
$
Points to the end of string. The pattern before it will be applied to the end of the string but not to the other partsYou can restrict your pattern to match only those substrings that include the end of string by using $:
12
console.log(!!"foo bar".match(/bar$/)) // true console.log(!!"bar foo".match(/bar$/)) // false If you need to match "$" literally than you have to escape it with backslash:
12345
console.log(!!"foo$".match(/foo\$/)) // true console.log(!!"foo$".match(/foo\$$/)) // true console.log(!!"foo$".match(/foo$/)) // false console.log(!!"$foo".match(/\$foo/)) // true console.log(!!"$foo".match(/$foo/)) // false 