DEV Community


Multiline flag in regex

Mehul Lakhanpal
Full stack Developer | Micro-blogging on Web Development at | Creator of File Ops, Note Box, GitHub Marker
Originally published at ・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 for daily posts.


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

Discussion (0)

Forem Open with the Forem app