regex question: backreferences in brackets
Tim Roberts
timr at probo.com
Sun Dec 30 17:17:06 EST 2001
Jeremy Jones <cypher_dpg at yahoo.com> wrote:
>
>I want to be able to match any character other than a character that I already matched and have a named (or numbered) group for. For example:
>
>"""
>match_string = 'XXX|1|22|333|4444:'
>test_compile = re.compile(r'XXX(.)[^|]{1}\1[^|]{2}\1[^|]{3}\1[^|]{4}(.)')
>mymatch = test_compile.match(match_string)
>if mymatch:
> print "Found a match"
> print mymatch.group(0)
>else:
> print "No match found"
>"""
>
>The format of the strings that I am trying to match are 3 specific
>characters followed by some delimter followed by N number of characters
>other than the delimiter followed by the delimiter, etc.
For this specific problem, wouldn't a string.split solution be more
efficient and understandable?
matches = match_string.split( match_string[3] )
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list