For a little idea of what the project is, I'm trying to make a markup language that compiles to HTML/CSS. I plan on formatting links like this: @(link mask)[(link url)], and I want to find all occurrences of this and get both the link mask and the link url.
I tried using this code for it:
The dfault behavior of a regular expression is "greedy matching". This means each
.* will match as many characters as it can.
You want them to instead match the minimal possible number of characters. To do that, change each
.* into a
.*?. The final question mark will make the pattern match the minimal number of characters. Because you anchor your pattern to a
] character, it will still match/consume the whole link correctly.