Multiline flag in regex

ml318097

Mehul Lakhanpal

Posted on April 12, 2021

Multiline flag in regex
const str = `
1. Bread
2. Apples
3. Milk
`;

const regex = /^\d\./gm;
console.log(str.match()); // [ '1.', '2.', '3.' ]
Enter fullscreen mode Exit fullscreen mode

m flag enables to match at the start and end of every line.
The regex matches lines that start with number followed by comma


Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

💖 💪 🙅 🚩
ml318097
Mehul Lakhanpal

Posted on April 12, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Multiline flag in regex
regex Multiline flag in regex

April 12, 2021