As a .Net developer I’m almost addicted to regular expressions to solve common string problems. The advantage of regular expressions are that lot of tools and languages use them. A drawback is that they can be very complex and hard to read (documenting them is key). Another drawback is that every language has its own implementation / dialect.

Javascript regular expression differs from the .Net engine that I’m familiar with… take grouping for example; .Net uses explicit named capturing, but Javascript uses implicit capturing. I needed to add an alt to all the captured “src”-attributes present in a string:

//Regex in .Net <a.*?src="(?<1>[^"]*?)".*?</a>
//Javascript counter part
var x = /<a .*?<img.*?src="([^"]*?)".*?>.*?</a>/g

//Replacement (the same):
<img src="$1" alt="Source: $1" />

Groups are captured by columns, but are not explicitly named. When regex replacement is used, the engine will match the $n  to the n-th group. You can reuse the group in the regex itself by adding /1/ to the regex. has a small tool to test regexes for javascript, might be useful.