in reply to silly regex question
i'm trying to write a regular expression that will replace all single quotes (') not contained in <%...%> tags with a separate string.
The recipe I've used for years now: match the skip sequence, or the string you want to match, in that order. If you found a skip sequence, replace the matched string by itself, otherwise, replace by whatever you want.
A conversion to simple code:
I didn't have to put parens around the second pattern in this simple case, but it's the way to capture the matched text in case you want to match more than a single literal string, and you want to know what you matched: it'll be in $2.<s/(<%.*?%>)|(')/$1 || 'test'/seg;
|
---|