In ECMAScript, and here’s my regex that i’m working with:
replace(/\[(.+)\s+->\s+([^\]]+)]/g, '<a class=adl_btnlnk href="$2">$1</a>');
That’s fine for the following string:
"[INNER\"',';!@#$%^&*gobbeldygook -> -> -> http://li.nk?u=r&l]"
…It does exactly what I need. But what about when I have:
"[INNER\"',';!@#$%^&*gobbeldygook -> -> -> http://li.nk?u=r&l] laksjfalksdjf98723&*(*&(*@&#$ [foo -> http://li.nk]"
It results in one, broken, link:
"<a class=adl_btnlnk href="http://li.nk">INNER"',';!@#$%^&*gobbeldygook -> -> -> http://li.nk?u=r&l] laksjfalksdjf98723&*(*&(*@&#$ [foo</a>"
How can I make it into:
"<a class=adl_btnlnk href="http://li.nk?u=r&l">INNER"',';!@#$%^&*gobbeldygook -> -></a> laksjfalksdjf98723&*(*&(*@&#$ <a class=adl_btnlink href="http://li.nk">foo</a>"
You can make your
+quantifiers take as less as possible by appending a?. But you have to alter your regexp a bit so that it takes as much as possible excluding]characters for the first group. Also, the last group shouldn’t include the arrows: