Re: [Tutor] regex grouping/capturing

2013-06-18 Thread Albert-Jan Roskam
- Original Message - > From: Oscar Benjamin > To: Tutor@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 wrote: >>  from pygments.lexer impor

Re: [Tutor] regex grouping/capturing

2013-06-18 Thread Oscar Benjamin
On 18 June 2013 09:27, Albert-Jan Roskam 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'\[.*

Re: [Tutor] regex grouping/capturing

2013-06-18 Thread Albert-Jan Roskam
- Original Message - > From: Andreas Perstinger > To: "tutor@python.org" > Cc: > Sent: Friday, June 14, 2013 2:23 PM > Subject: Re: [Tutor] regex grouping/capturing > > On 14.06.2013 10:48, Albert-Jan Roskam wrote: >> I am trying to create a pygmen

Re: [Tutor] regex grouping/capturing

2013-06-14 Thread Andreas Perstinger
On 14.06.2013 10:48, Albert-Jan Roskam wrote: I am trying to create a pygments regex lexer. Well, writing a lexer is a little bit more complex than your original example suggested. > Here's a simplfied example of the 'set' command that I would like to > parse. s = 'set workspace = 6148 he

Re: [Tutor] regex grouping/capturing

2013-06-14 Thread Albert-Jan Roskam
- Original Message - > From: Andreas Perstinger > To: tutor@python.org > Cc: > Sent: Thursday, June 13, 2013 8:09 PM > Subject: Re: [Tutor] regex grouping/capturing > > On 13.06.2013 17:09, Albert-Jan Roskam wrote: >> I have a string of the form "requir

Re: [Tutor] regex grouping/capturing

2013-06-13 Thread Andreas Perstinger
On 13.06.2013 17:09, Albert-Jan Roskam wrote: I have a string of the form "required optional3 optional2 optional1 optional3" ('optional' may be any kind of string, so it's not simply 'optional\d+'. I would like to use a regex so I can distinguish groups. Desired outcome: ('required', 'optional3',

[Tutor] regex grouping/capturing

2013-06-13 Thread Albert-Jan Roskam
  Hello,   I have a string of the form "required optional3 optional2 optional1 optional3" ('optional' may be any kind of string, so it's not simply 'optional\d+'. I would like to use a regex so I can distinguish groups. Desired outcome: ('required', 'optional3', 'optional2', 'optional1', 'optiona