I am trying to find HTML tags, via PHP ereg, that has a {xxx}
right before the closing tag - where xxx
can be [A-Za-z0-9_\-]*
.
For example: <p>xxxx</p><p>yyyy{asdf}</p>
This is the best I could come up with: /<([\w]+)([^>]?)>([^{]*)\{([^}]+)\}<\/\1>/is
The problem is though, that it will match group 3 will have xxxx</p><p>yyyy
, and I only want 开发者_C百科yyyy
in this case.
Hope anybody can help, cheers, Egil.
Ps. Sorry for the useless title, could not think of anything better.
Add a ?
after each +
and *
in your regex. This will make the match less greedy.
Else try adding <>
to the negative character classes [^{<>]*
and [^}<>]*
to exclude tags in between there.
精彩评论