有一个快速的方法来添加前缀到所有CSS类& ID的? [英] There a quick way to add prefixes to all CSS classes & ID's?

查看:63
本文介绍了有一个快速的方法来添加前缀到所有CSS类& ID的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要快速添加前缀到我的所有类和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测试
http://regexr.com?2ugv1


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 CSS http://regexr.com?2ugv1

这篇关于有一个快速的方法来添加前缀到所有CSS类&amp; ID的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆