DEV Community

loading...

Multiline flag in regex

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read
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

Discussion (0)

pic
Editor guide