问题描述
我需要快速添加前缀到我的所有类和ID,它是一个相当大的CSS文件。我在想一个快速regex字符串,但到目前为止我失败了。
\#([A-z0-9] +){
prefix_ $ 1,但不会考虑:
#id {
#id.class
#id,
等。我不能只是替换所有#[a-z0-9],因为它会尝试抓取背景颜色等。
我还需要替换所有
您可以搜索:
\。( - ?[_ a-zA-Z] + [_ a-zA-Z0-9 - ] *)[^}] + {
/ p>
\#( - ?[_ a-zA-Z] + [_ a-zA-Z0-9 - ] *)[^} + {
应该找到您的所有类名和ID名称
,使用这个:
(?< =#| \。)( - ?[_ a-zA-Z] + [ zA-Z0-9 - ] *)(?= [^}] + {)
到google的CSS测试
I need to quickly add prefixes to all of of my classes and ID's and it's quite a large CSS file. I was thinking a quick regex string but so far I've failed. Any ideas?
I've tried simple things like:
\#([A-z0-9]+) {
Which will let me replace with #prefix_$1 but it doesn't take into account:
#id {
#id.class
#id,
etc. I can't just replace all #[a-z0-9] because it will attempt to grab background-colors and so on.
I also need to replace all the classes, which is even more confusing for me.
You could search:
\.(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)[^}]+{
\#(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)[^}]+{
Should find all your class names and id names
With RegExr, use this:
(?<=#|\.)(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)(?=[^}]+{)
Edit:Here's a link to a test on google's CSShttp://regexr.com?2ugv1
这篇关于有一个快速的方法来添加前缀到所有CSS类& ID的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!