开发者

Regex html tags

I'm trying to figure out the regex for the following:

String</td><td>[number 0-100]%</td><td&g开发者_运维技巧t;[number 0-100]%</td><td>String</td><td>String</td>

Also, some of these td tags may have style attributes at some point. I tried this:

String<.*>

and that returned

String</td>

but trying

String<.*><.*>

returned nothing. Why is this?


You probably shouldn't be trying to use a regex to parse HTML, because that way lies madness.


(.+)</td><td>(1?\d?\d)%</td><td>(1?\d?\d)%</td><td>(.+)</td><td>(.+)</td>


use Character class, like <td[^>]*> if <td> or <td class="abc">


Try the following:

(.+)(<[^>]+>){2}(1?\d?\d)%(<[^>]+>){2}(1?\d?\d)%(<[^>]+>){2}(.+)(<[^>]+>){2}(.+)<[^>]+>

You can test it here.

EDIT: Although this will work for most of the time, if there is > character in one attribute of the tag, this regex won't work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜