[TxMt] Python interpretation of raw strings as regexes

Fabry Nicholas F. nick at superb-sublime.com
Mon Aug 13 16:38:27 UTC 2007


>
>
>
>
>> I'm more and more convinced as time goes on that we should just  
>> stop trying to interpret raw strings as regexps.
>>
>>
>
> I think you are probably right.  Does anyone else have an opinion  
> on this?
>
>
Well - as you pointed out previously, raw strings were introduced  
into Python for the specific purpose of making writing regexps  
easier.  If we don't interpret raw strings as regexes, what will we  
interpret as regexes in Python, then?  Or will we just ditch regex  
syntax highlighting from Python altogether?

Perhaps we need some sort of obvious marker on the same line to  
indicate that a raw string should be interpreted as a regex.  Regexes  
in Python are pretty obvious when being used - a very common way is  
to compile a regex via re.compile([raw string]), and the other common  
way is to call other functions in the regex module, ala re.findall 
(r'\bFig\b'), for instance.

So, perhaps raw strings should only be interpreted as regexes when  
directly preceded by re.[function]( - while this would not get  
everything we might want to be interpreted as a regex, it would  
capture some of the most common use cases.

Nick




More information about the textmate mailing list