Re: re.sub and empty groups

2007-01-16 Thread harvey . thomas
Hugo Ferreira wrote: > Hi! > > I'm trying to do a search-replace in places where some groups are > optional... Here's an example: > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola").groups() > ('ola', None) > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola|").groups() > ('ola', '')

Re: re.sub and empty groups

2007-01-16 Thread harvey . thomas
Hugo Ferreira wrote: > Hi! > > I'm trying to do a search-replace in places where some groups are > optional... Here's an example: > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola").groups() > ('ola', None) > > >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola|").groups() > ('ola', '')

re.sub and empty groups

2007-01-16 Thread Hugo Ferreira
Hi! I'm trying to do a search-replace in places where some groups are optional... Here's an example: >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola").groups() ('ola', None) >> re.match(r"Image:([^\|]+)(?:\|(.*))?", "Image:ola|").groups() ('ola', '') >> re.match(r"Image:([^\|]+)(?:\|(.*))?