开发者

regexp for html p tag with style element

开发者 https://www.devze.com 2023-03-28 03:17 出处:网络
Sorry i\'m new for regexp, so i need a regexp for this type of tag, exactly for this: <p style=\"font-family: Georgia;\">Text</p>

Sorry i'm new for regexp, so i need a regexp for this type of tag, exactly for this:

<p style="font-family: Georgia;">Text</p>

I have a regexp that suits for all p tags, regexp for all p tag is: <\s*p[^>]*>([^<]*)<\s*\/\s*p\s*>/ found it on this site. I tried to figure out by myself, i wrote this: <\s*p[\"\^font\-\family\:\()\Georgia开发者_运维技巧\;\$\"\]*>([^<]*)<\s*\/\s*p\s*>/ but i know it's wrong can anyone help me :) I need regexp exactly for this piece: style="font-family: Georgia;" Thank you.


If you just want to match style="font-family: Georgia;" use this: \w+=".+"

For matching the the entire thing \s*<p \w+=".+">([^<]*)</p>\s* can do the trick. This will capture all paragraphs with exactly one attribute with a quoted value.. Not really flexible. If you only want to capture on paragraphs with exactly the font-family georgia style use \s*<p style="font-family: Georgia;">([^<]*)</p>\s*

If you find yourself using a lot of regular expressions to "parse" html, a HTML parser might save yourself a lot of trouble. Php's DOM class can parse html.

0

精彩评论

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