本文介绍了如何从文件中编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 使用html解析器 use_raw ='%s%s'%(use_raw,aux) 这是我如何解释黑色,但在这里我想排除灰色。解决方案 说明 识别灰色 所有灰色十六进制颜色代码都包含 3个2位数或 3个相同数字 。例如#151515 ,#1C1C1C ,#2E2E2E ,#424242 ,#555 , #EEE .....这就是我们如何将它们识别为灰色。 确定字符串是否符合'gray'格式 因此,我会使用正则表达式。以下正则表达式将匹配所有以#开头的字符串,并且包含3个相同的连续2位数字字母数字字符集。因此,匹配所有的灰色。 ^#([a-fA-F0-9] {1,2})\1 \ 1 应用Python import re pattern = re.compile(^#([a-fA-F0-9] {1,2})\1\1 $) pattern.match(aux) 有关正则表达式的Python文档: https://docs.python.org/3/library/re.html http://www.rapidtables.com/web/color/gray-color.htm 如何查找3个或更多连续字符? 检查字符串是否匹配模式 li> http://www.xcprod.com/titan/XCSB-DOC/hex。 html Blender 的评论关于3位十六进制代码 Using html parseruse_raw = '%s%s' % (use_raw, aux)This how i am exlcuding black, but here i want to exclude grey too. 解决方案 ExplanationIdentifying 'grey'All grey hex color codes have 3 sets of 2 digits or 3 identical digits. e.g. #151515, #1C1C1C, #2E2E2E, #424242, #555, #EEE..... and this is how we can identify them as grey. Determining if string meets 'grey' formatTherefore I would use a regex. The following regular expression will match all strings, that start with a #, and contain 3 identical consecutive sets of 2 digit alpha-numeric characters. Hence match all greys.^#([a-fA-F0-9]{1,2})\1\1$Applying with Pythonimport repattern = re.compile("^#([a-fA-F0-9]{1,2})\1\1$")pattern.match(aux)See the Python documentation on regular expressions: https://docs.python.org/3/library/re.htmlReferences:http://www.rapidtables.com/web/color/gray-color.htmHow to find 3 or more consecutive characters?Check if string matches patternhttp://www.xcprod.com/titan/XCSB-DOC/hex.htmlBlender's comment about 3-digit hex codes 这篇关于如何从文件中编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-02 20:56