✅ – venus – 08-46 May 24

Hey, I am trying to catch all mdx headings (## First Heading, ### Third Heading, etc.) but only the phrase that comes after ## . Could I get some help with regex that can handle it? Thanks. I've found this one, but sadly doesn't work for my case
^(### |## )(.*)\n
^(### |## )(.*)\n
String: \r\n## First Heading\r\n\r\nLorem Ipsum.\r\n\r\n### Second Heading\r\n\r\nLorem Ipsum Lorem Ipsum.\r\n\r\n### Third Heading\r\n\r\nLorem Ipsum Lorem Ipsum Lorem Ipsum.\r\n
S
ScriptyChris695d ago
you want to ignore new line characters (\r\n)?
V
venus695d ago
Basically I just want to get all headings like: First Heading Second Heading Third Heading
S
ScriptyChris695d ago
'\r\n## First Heading\r\n\r\nLorem Ipsum.\r\n\r\n### Second Heading\r\n\r\nLorem Ipsum Lorem Ipsum.\r\n\r\n### Third Heading\r\n\r\nLorem Ipsum Lorem Ipsum Lorem Ipsum.\r\n'
.match(/#+ (\w+\s\w+)/g) /* OR: /#+ ([A-Za-z ]+)/g */
.map(fragment => fragment.replace(/[# ]+/, ''));
// ['First Heading', 'Second Heading', 'Third Heading']
'\r\n## First Heading\r\n\r\nLorem Ipsum.\r\n\r\n### Second Heading\r\n\r\nLorem Ipsum Lorem Ipsum.\r\n\r\n### Third Heading\r\n\r\nLorem Ipsum Lorem Ipsum Lorem Ipsum.\r\n'
.match(/#+ (\w+\s\w+)/g) /* OR: /#+ ([A-Za-z ]+)/g */
.map(fragment => fragment.replace(/[# ]+/, ''));
// ['First Heading', 'Second Heading', 'Third Heading']
V
venus695d ago
Thank you. 😉
UU
Unknown User695d ago