0

I'm trying to parse markdown with (\*\*|__).*?(\*\*|__). The problem I'm facing is, I will match a string that starts with for example capture group 1 (**) but ends with another (__). How can I make sure it uses the group which matched at the start, also at the end? Thanks :)

pushkin
  • 9,575
  • 15
  • 51
  • 95
peter123
  • 181
  • 10

1 Answers1

0

The solution is to replace the second capture group with \1.

For details see this comment by anubhava:

Use /(\*\*|__).*?\1/

And this comment by Wiktor Stribiżew:

This explains what \1 is.

dbc
  • 104,963
  • 20
  • 228
  • 340
peter123
  • 181
  • 10