Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'matches': 0.07; 'boundaries': 0.09; 'library': 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'fuzzy': 0.16; 'match:': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'reason.': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'skip:| 20': 0.16; 'string': 0.17; 'fix': 0.17; 'module': 0.19; 'discussion': 0.20; 'import': 0.21; 'error.': 0.21; "python's": 0.23; "i've": 0.23; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:# 10': 0.27; 'mix': 0.27; "doesn't": 0.28; 'initiate': 0.29; 'received:192.168.1.3': 0.29; 'code': 0.31; 'received:84': 0.32; 'could': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'front': 0.33; 'thanks': 0.34; 'there': 0.35; 'modules': 0.36; 'author': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'behind': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'help': 0.40; 'your': 0.60; 'p.s.': 0.63; 'making': 0.64; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'counts': 0.81; 'matthew,': 0.84; 'reply- to:addr:python.org': 0.84; 'tied': 0.93 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=IekFqBWa c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=DKcI9XZsuF4A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=wAolkzV8IT3RjTvUbFYA:9 a=wPNLvfGTeEIA:10 a=Q8_jkyt3DRob-YpK:21 a=-ISjyME5BZ1tIA65:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Tue, 07 Aug 2012 18:12:06 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Q on regex References: <1344336754.13108.2@numa-i> In-Reply-To: <1344336754.13108.2@numa-i> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344359523 news.xs4all.nl 6942 [2001:888:2000:d::a6]:55556 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26730 On 07/08/2012 11:52, Helmut Jarausch wrote:> Hi Matthew, > > how to fix the code below to match 'Hellmuth' instead of ' Hellmut' ? > > A negative look behind in front of the pattern doesn't help since it > counts > as an error. One would need a means to mix a required match with a > fuzzy match. > > > #!/usr/bin/python3 > import regex > > Author= regex.compile(r'(?:Helmut){e<=2}') > > R=Author.search('Jarausch Hellmuth') > if R : > print("matching string : |{0}|".format(R.group())) > # matches ' Hellmut' > else : > print("nothing matched") > There are two ways you could do it. One way is to put word boundaries outside the fuzzy match: Author = regex.compile(r'\b(?:Helmut){e<=2}\b') The other way is to use the 'ENHANCEMATCH' flag (or '(?e)' in the pattern), which tells it to 'enhance' the match by reducing the number of errors: Author = regex.compile(r'(?e)(?:Helmut){e<=2}') > > Many thanks for a hint, > Helmut. > > P.S. I've tried to initiate a discussion on adding your module to the > current standard library on C.L.P. > The problem with adding it to the standard library is that any releases would be tied to Python's releases and I would have much less leeway in making changes. There are a number of other modules which remain outside the standard library for just that reason.