Kre*_*dns 5 python regex xml gedit
我正在尝试扩展该python.lang文件,以便它可以使方法突出__init__显示。我一直在尝试想出一个能够匹配所有__privateMethods().
这python.lang是一个 XML 文件,包含 python 文件的所有突出显示规则。前任:
<context id="special-variables" style-ref="special-variable">
   <prefix>(?<![\w\.])</prefix>
   <keyword>self</keyword>
   <keyword>__name__</keyword>
   <keyword>__debug__</keyword>
</context>
我如何扩展它以使其匹配双下划线?
[解决方案]:我添加到我的python.lang文件中的内容(如果有人感兴趣):
首先,您需要在定义样式的顶部附近添加此行。
<style id="private-methods" _name="Private Methods" map-to="def:special-constant"/>
然后您将添加卡尔斯在他的答案中提供的正则表达式:
<context id="private-methods" style-ref="private-methods">
    <match>(__[a-zA-Z_]*(__)?)</match>
</context>
这是完成后的样子!

它应该是:
(__[a-zA-Z0-9_]*(__)?)
为了匹配以下所有内容:
__hello()
__init__()
__this_is_a_function()
__this_is_also_a_function__()
__a_URL2_function__()
| 归档时间: | 
 | 
| 查看次数: | 4095 次 | 
| 最近记录: |