I have the following text in a variable in PHP:
[e https://google.es]Lorem ipsum[/e]
And I want to transform it into:
<a href="https://google.es">Lorem ipsum</a>
I have other tags that are not so complex and I have been able to do them with a simple str_replace, but this one requires regex (I guess) and making it enter [e
and ]
there can be any content, you know what I mean.
This is the regex you are looking for:
\[e (.+)\](.*)\[\/e\]
It looks complicated because the characters have to be escaped
[
and]
because they are regex reserved characters, but it is quite simple:\[e
start with [ey a space. If there can be multiple spaces there, you can use \s+(.+)
the first group of what you want to extract, a sequence of 1 or more characters.\]
clasp closure(.*)
the second group you want to extract, a sequence of 0 or more characters\[/e\]
the closure of the tag eI'm not very familiar with how PHP works with regex, but the idea is that in groups 1 and 2 you are left with the data you need, then to create your new string, you should do something like:
'<a href="'.$1.'">'.$2.'</a>'
Edit: in PHP it would be something like this: