用于匹配包含非白色 space 字符的元描述标签的正则表达式

Regex to match meta description tags that are containing non white space characters

嗨,你们这些聪明的 RegEx 魔术师!

我正在尝试创建一个与源代码中的元描述标签相匹配的正则表达式,该标签不为空或不只包含空格。

例如这应该匹配:

<meta name="description" content="This is my super great meta description &amp; I love it so much!"/>
<meta name="description" content=" This is my super great meta description &amp; I love it so much!"/>
<meta name="description" content="This is my super great meta description &amp; I love it so much! "/>

这例如不应该匹配:

<meta name="description" content=""/>
<meta name="description" content=" "/>
<meta name="description" content="  "/>
<meta name="description" content="
"/>

到目前为止我已经想到了这个,但这当然还不够,我真的不知道如何替换通配符...

#<\s*meta[^>]\s*name\s*=\s*("|')description("|')\s*content\s*=\s*("|').*("|')?\/?[^>]*>#i

谁能帮忙?

非常喜欢和感谢!

您的正则表达式似乎过于复杂而且不正确。

如果内容属性仅包含零个或多个空白字符,您可以使用此 (?!\s*") 否定前瞻来拒绝匹配。在所有正则表达式中,

<meta\s+name="description"\s+content="(?!\s*").*"\/>

Demo