I wrote this regexp to capture the strings below.
\!\[(.*?)?\]
All the strings below should match and return an optional string that's inside the first set of square brackets.
![]
![caption]
![]()
![caption]()
![caption][]
The problem is that this string also matches and returns ][
because the regex thinks it's between the first [
and last ]
.
![][] // Should not match, but does and returns "]["
How do I fix this?