RegexpGarden












- Garden Text Representation
12345
let garden = [ "Rosemary", "Rose", "Primrose", "Rice", "Rose-of-Sharon", "Christmas Rose"];- Code Editor
- Log
123456
for (const plant of garden) {if (plant.match(//i) {cut(plant);}}Lesson task •
Cut just "rose", without cultivars
Cover full string
^...$
Here is a trick: to force your regexp to be compared against full string but not it’s substrings, enclose your regexp between ^ and $1234
console.log(!!"foo bar".match(/^foo bar$/)) // true console.log(!!"foo bar baz".match(/^foo bar$/)) // false console.log(!!"^foo bar$".match(/^foo bar$/)) // false console.log(!!"^foo bar$".match(/\^foo bar\$/)) // true 