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 :)
Asked
Active
Viewed 67 times
0
-
2Use `/(\*\*|__).*?\1/` – anubhava Apr 23 '21 at 16:41
-
2could you please explain what `\1` and `(?:(?!\1).)*?\1` does? I'm trying to learn from this, not just copy and paste. But thanks! :) – peter123 Apr 23 '21 at 16:43
-
1[This](https://stackoverflow.com/questions/928179/matching-on-repeated-substrings-in-a-regex) explains what `\1` is. – Wiktor Stribiżew Apr 23 '21 at 16:47
1 Answers
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.
-
1
-
1sorry, it was automatic, my mistake, i think i clicked on the wrong option – SpaceDogCS Apr 24 '21 at 12:19