简体   繁体   English

在CSS文件中查找重复的十六进制值的正则表达式

[英]Regular expression to find repeating hex values in css files

I have a large amount of CSS files that I've extracted the hex colour values from. 我有大量的CSS文件已从中提取出十六进制颜色值。 What I'd like to do now is to strip out any duplicates not found by uniq. 我现在想做的是剔除uniq找不到的所有重复项。 For example, I have: 例如,我有:

#ccc
#cccccc
#eee
#eeeeee

What I'd like to do is to run a regular expression against the file to identify the #cccccc and #eeeeee (or any other similar) strings, remove the last three characters so I can then run uniq against them to remove the new duplicates. 我想对文件运行一个正则表达式,以识别#cccccc和#eeeeee(或任何其他类似的)字符串,删除最后三个字符,这样我就可以对它们运行uniq来删除新的重复项。

How can I do this? 我怎样才能做到这一点?

Thanks! 谢谢!

You could match (make sure it's case insensitive): 您可以匹配(确保不区分大小写):

#([\da-f])\1([\da-f])\2([\da-f])\3\b

and replace it with: 并替换为:

#$1$2$3

For example in Perl written as: 例如在Perl中写为:

s/#([\da-f])\1([\da-f])\2([\da-f])\3\b/#$1$2$3/gi

Example input: 输入示例:

#ccc
#cccccc
#123
#112233
#123123

Output: 输出:

#ccc
#ccc
#123
#123
#123123

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM