Short version: I need mysql code that will change
[href="http://a-random-domain.com"]hyperlink[/href]
into
<a href="http://a-random-domain.com">hyperlink</a>
- without messing up the domain part, and
- without accidentally converting any unrelated instances of "] that might occur in the text of a field.
- Domain will be unique/different every time it is encountered.
Long version: I am migrating an old database for use with a new application. The old database has a text field that includes content such as:
This is a data field with a [href="http://somedomain.com"]hyperlink[/href] and more data and possibly other hyperlinks.
I need to update it to standard html, e.g.
This is a data field with a <a href="http://somedomain.com">hyperlink</a> and more data and possibly other hyperlinks.
Fixing the [href= and [/href] is simple enough using REPLACE
update table set field = replace(field, '[href=', '<a href=');
but I get tripped up on the "] closing bracket of the a href tag. And in the database there are other instances of "] that shouldn't be modified, so I can't just replace on "]
Does mysql have some sort of regex "lookahead" or other way to accomplish this?
Thanks much!