正则表达式提取CSS之间的内容
所以我试图做到这一点,以便我从 css 类中获取所有文本。
例如,
h1 {
font-weight: bold;
}
我需要获取一个包含“font-weight:bold;”的字符串
我还需要确保这不会与其他课程混淆。基本上想象一下它位于一个巨大的 css 文件的中间。我怎样才能上那门课呢?
(可以忽略 h1.blah 或 h1 的变体等内容。)
So I'm trying to make it so the I get all the text out of a css class.
For instance,
h1 {
font-weight: bold;
}
I need to get a string which will contain "font-weight: bold;"
I also need to make sure this doesn't get mixed up with other classes. Basically imagine that was in the middle of a huge css file. How would I get just that class.
(it is ok to ignore things such as h1.blah or variations of h1.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将是获取标准 h1 声明内任何内容的正则表达式。它考虑了间距等。您可能想要更精细的结果,但问题缺乏进一步解决问题所需的特异性。
/h1\s*{(.+?)}/m
This would be the RegEx to grab anything inside of a standard h1 declaration. It takes into account spacing and so forth. You probably want more finely-tuned results, but the question lacks the specificity necessary to address the problem further.
/h1\s*{(.+?)}/m