[Tutor] regex grouping/capturing

Albert-Jan Roskam fomcl at yahoo.com
Tue Jun 18 12:56:48 CEST 2013





----- Original Message -----

> From: Oscar Benjamin <oscar.j.benjamin at gmail.com>
> To: Tutor at python.org
> Cc: 
> Sent: Tuesday, June 18, 2013 12:42 PM
> Subject: Re: [Tutor] regex grouping/capturing
> 
> On 18 June 2013 09:27, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>>  from pygments.lexer import RegexLexer, bygroups from pygments.token import 
> * class IniLexer(RegexLexer): name = 'INI' aliases = ['ini', 
> 'cfg'] filenames = ['*.ini', '*.cfg'] tokens = { 
> 'root': [ (r'\s+', Text), (r';.*?$', Comment), 
> (r'\[.*?\]$', Keyword), 
> (r'(.*?)(\s*)(=)(\s*)(.*?)$', bygroups(Name.Attribute, Text, 
> Operator, Text, String)) ] }
> 
> I'm not sure how you sent this email but I'm assuming it wasn't
> supposed to look like it does above. Did you compose/send this as
> plain-text or html?


yikes! Sorry about that. It seems that even in plain-text mode copy-pasted text gets mangled by yahoo. That happens *after* sending the mail. Here is the correctly indented code (website-->notepad-->yahoo):


from pygments.lexer import RegexLexer, bygroups
from pygments.token import *

class IniLexer(RegexLexer):
    name = 'INI'
    aliases = ['ini', 'cfg']
    filenames = ['*.ini', '*.cfg']

    tokens = {
        'root': [
            (r'\s+', Text),
            (r';.*?$', Comment),
            (r'\[.*?\]$', Keyword),
            (r'(.*?)(\s*)(=)(\s*)(.*?)$',
             bygroups(Name.Attribute, Text, Operator, Text, String))
        ]
    }


More information about the Tutor mailing list