Does Regex match double underscores?

I am trying to expand a python.lang file python.lang that it highlights methods like __init__ . I tried to come up with a regex that would fit all __privateMethods() .

python.lang is an XML file containing all allocation rules for python files. Example:

 <context id="special-variables" style-ref="special-variable"> <prefix>(?&lt;![\w\.])</prefix> <keyword>self</keyword> <keyword>__name__</keyword> <keyword>__debug__</keyword> </context> 

How can I expand this to match double underscores?


[SOLUTION]: What I added to my python.lang file (if anyone is interested):

First you need to add this line closer to the top where the styles are defined.

 <style id="private-methods" _name="Private Methods" map-to="def:special-constant"/> 

Then you add the Regex that Carles provided in his answer :

 <context id="private-methods" style-ref="private-methods"> <match>(__[a-zA-Z_]*(__)?)</match> </context> 

And this is what it looks like when you are done!

enter image description here

+4
source share
2 answers

It should be:

 (__[a-zA-Z0-9_]*(__)?) 

To match all of the following:

 __hello() __init__() __this_is_a_function() __this_is_also_a_function__() __a_URL2_function__() 
+4
source

Compare your previous case with the following ( rubular example ):

 (^__[az]*__$) 
+1
source

Source: https://habr.com/ru/post/1338492/


All Articles