REPOST: Re: 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.
========= WAS CANCELLED BY =======:
Path: news.sol.net!spool0-nwblwi.newsops.execpc.com!newsfeeds.sol.net!newspump.sol.net!news.maxwell.syr.edu!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: Tim Roberts <timr at probo.com>
Newsgroups: comp.lang.python
Subject: cmsg cancel <gg4v2uovpvcr7p1nc03ne5uumng1egbbbt at 4ax.com>
Control: cancel <gg4v2uovpvcr7p1nc03ne5uumng1egbbbt at 4ax.com>
Date: Mon, 31 Dec 2001 03:18:30 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.gg4v2uovpvcr7p1nc03ne5uumng1egbbbt at 4ax.com>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009774041 27193 211.57.49.2 (31 Dec 2001 04:47:21 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 04:47:21 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)
This message was cancelled from within Mozilla.
More information about the Python-list
mailing list