开发者

Help with regex html plus with extra string at the end

开发者 https://www.devze.com 2023-02-17 13:16 出处:网络
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_\\-]*.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消