I’m using jquery to sort a table column of names. I’m all set with the js, just a little stuck on the regex command.
Example of what I’m looking for:
<a href="bac">John <strong>Smith</strong></a> => Smith</strong></a>
<a href="abc">John <strong>La Smith</strong></a> => La Smith</strong></a>
My current statement that needs some polishing…
/<a.*>.+ /i
Assuming you’re using replace in JavaScript, the following would work:
gives
respectively.
Now, this is a very rudimentary regex, w/ a lot of assumptions built in. It assumes that your links always have the last name inside the
<strong>. And that your links are always of this form.I’m not exactly sure how you plan to use this in your code, so I’ve just provided the regex in the replace.
The Regex itself is just
/<a.*?<strong>(.*?)<\/strong>.*?<\/a>/iwhich is:<a.*?<strong>Presumably, though, you’d want to use jquery to get the contents inside the link, which would mean that you could eliminate the
<aand<\/a>in the regex.