Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74050
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'else:': 0.03; 'matches': 0.07; 'string': 0.09; 'matched': 0.09; 'steps:': 0.09; 'subject:How': 0.10; 'python': 0.11; "'a',": 0.16; '.........': 0.16; 'displays.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'line)': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'reached,': 0.16; 'received:192.168.1.4': 0.16; 'regex,': 0.16; 'retry': 0.16; 'subsequently': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'have:': 0.19; '(the': 0.22; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'first,': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'rest': 0.29; "doesn't": 0.30; 'matching': 0.30; 'class': 0.32; 'says': 0.33; 'but': 0.35; 'there': 0.35; 'subject:?': 0.36; 'hi,': 0.36; 'ends': 0.38; 'to:addr:python-list': 0.38; 'skip:. 10': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'expression': 0.60; 'letters': 0.60; 'entire': 0.61; 'back': 0.62; 'reach': 0.63; 'email addr:gmail.com': 0.63; 'more': 0.64; 'finally': 0.65; 'subject:this': 0.83; 'conclude': 0.84; 'demonstrates': 0.84; 'fails,': 0.84; 'obvious.': 0.84; 'capture': 0.91; 'greedy': 0.91; 'imagine': 0.93 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=OZcWD3jY c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=u9EReRu7m0cA:10 a=-k01_FFYG7EA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=pGLkceISAAAA:8 a=Dmjgt6uUqW0v45E2aHgA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Sun, 06 Jul 2014 20:19:43 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: How to write this repeat matching? |
| References | <93a40570-00ed-4507-aa16-221d7e500468@googlegroups.com> |
| In-Reply-To | <93a40570-00ed-4507-aa16-221d7e500468@googlegroups.com> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11555.1404674388.18130.python-list@python.org> (permalink) |
| Lines | 54 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1404674388 news.xs4all.nl 2932 [2001:888:2000:d::a6]:45352 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74050 |
Show key headers only | View raw
On 2014-07-06 19:57, rxjwg98@gmail.com wrote:
> Hi,
> On Python website, it says that the following match can reach 'abcb' in 6 steps:
>
> .............
> A step-by-step example will make this more obvious. Let's consider the expression
> a[bcd]*b. This matches the letter 'a', zero or more letters from the class [bcd],
> and finally ends with a 'b'. Now imagine matching this RE against the string
> abcbd.
>
> The end of the RE has now been reached, and it has matched abcb. This
> demonstrates how the matching engine goes as far as it can at first, and if no
> match is found it will then progressively back up and retry the rest of the RE
> again and again. It will back up until it has tried zero matches for [bcd]*, and
> if that subsequently fails, the engine will conclude that the string doesn't
> match the RE at all.
> .............
>
> I write the following code:
>
> .......
> import re
>
> line = "abcdb"
>
> matchObj = re.match( 'a[bcd]*b', line)
>
> if matchObj:
> print "matchObj.group() : ", matchObj.group()
> print "matchObj.group(0) : ", matchObj.group()
> print "matchObj.group(1) : ", matchObj.group(1)
> print "matchObj.group(2) : ", matchObj.group(2)
> else:
> print "No match!!"
> .........
>
> In which I have used its match pattern, but the result is not 'abcb'
>
That's because the example has 'abcb', but you have:
line = "abcdb"
(You've put a 'd' in it.)
> Only matchObj.group(0): abcdb
>
> displays. All other group(s) have no content.
>
There are no capture groups in your regex, only group 0 (the entire
matched part).
> How to write this greedy search?
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to write this repeat matching? rxjwg98@gmail.com - 2014-07-06 11:57 -0700
Re: How to write this repeat matching? MRAB <python@mrabarnett.plus.com> - 2014-07-06 20:19 +0100
Re: How to write this repeat matching? Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-06 13:26 -0600
Re: How to write this repeat matching? rxjwg98@gmail.com - 2014-07-07 06:30 -0700
Re: How to write this repeat matching? Anssi Saari <as@sci.fi> - 2014-07-07 18:48 +0300
Re: How to write this repeat matching? Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-07 10:18 -0600
csiph-web