RegexpGarden








- Garden Text Representation
1234
let garden = [
"Rosemary", "Barberry",
"Bearberry", "Primrose"
];
- Code Editor
- Log
123456
for (const plant of garden) {
if (plant.match(//i) {
cut(plant);
}
}
Lesson task •
Cut "barberry" and "bearberry"
Zero time or once
?
Repeats the previous token zero or one times123
console.log(!!"foobar".match(/^foo\w?bar$/)) // true
console.log(!!"foo4bar".match(/^foo\w?bar$/)) // true
console.log(!!"foo42bar".match(/^foo\w?bar$/)) // false
If you want to match "?" literally, escape it with backslash:
1
console.log(!!"?".match(/\?/)) // true