RegexpGarden












- Garden Text Representation
1234
let garden = [
"Rue", "Rose", "Rosemary",
"Rye", "Rice", "Primrose"
];
- Code Editor
- Log
123456
for (const plant of garden) {
if (plant.match(//i) {
fertilize(plant);
}
}
Lesson task •
Fertilize plants which names consist of exactly 4 letters
Exactly N times
{n}
Repeats the previous token exactly N timesInstead of duplicating the same token several times, you can follow it with the custom quantifier: \d\d\d equals to \d{3}
Possible use-case: match all the numbers which are greater than 99:
123456
console.log(!!"98".match(/\d{3}/)) // false
console.log(!!"99".match(/\d{3}/)) // false
console.log(!!"100".match(/\d{3}/)) // true
console.log(!!"999".match(/\d{3}/)) // true
console.log(!!"1000".match(/\d{3}/)) // true
console.log(!!"1000000".match(/\d{3}/)) // true
As usual, if you need to match "{" or "}" literally, consider escaping it with the backslash:
12
console.log(!!"{".match(/\{/)) // true
console.log(!!"}".match(/\}/)) // true