[Tutor] RE Silliness

spir denis.spir at free.fr
Sun Jan 4 23:08:07 CET 2009


On Sun, 04 Jan 2009 14:09:53 -0500
bob gailer <bgailer at gmail.com> wrote:

> Omer wrote:
> > I'm sorry, burrowed into the reference until my eyes bled.
> >
> > What I want is to have a regular expression with an optional ending of 
> > "<br>"
> >
> > (For those interested,
> > urlMask = r"http://[\w\Q./\?=\R]+"
> > is ther version w/o the optional <br> ending.)
> >
> > I can't seem to make a string optional- only a single character via 
> > []s. I for some reason thuoght it'll be ()s, but no help there- it 
> > just returns only the <br>. Anybody?
> >
> urlMask = r"http://[\w\Q./\?=\R]+(<br>)?"
> 
>  From the docs: ? Causes the resulting RE to match 0 or 1 repetitions of 
> the preceding RE. ab? will match either 'a' or 'ab'.
> 
> 

Maybe Omer had not noted that a sub-expression can be grouped in () so that an operator (?+*) applies on the whole group.
Denis

------
la vida e estranya


More information about the Tutor mailing list