I made a regular expression that matches for title="..."
in <a>
; unfortunately, it also matches for title="..."
in <img/>
.
Is there a way to tell the regular expression to ONLY look for title="..."
in <a>
? I can't use a look-behind method like (?<=<a\s+)
because they're NOT supported in JavaScript.
Here's my expression:
/((title=".+")(?=\s*href))|(title=".+")/igm;
The above expression matches the following:
As you can see, it matches for title="..."
found in <img/>
; I need the expression to exclude titles found in image tags.
Here is the link to the RegExp.
Also, if possible, I need to get rid of the title=" " around the title. So, only return title AFTER href
and title BEFORE href
. If not possible, I guess I can use .replace()
and replace it with ""
.
zx81's expression: