Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26730 > unrolled thread

Re: Q on regex

Started byMRAB <regex@mrabarnett.plus.com>
First post2012-08-07 18:12 +0100
Last post2012-08-07 18:12 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Q on regex MRAB <regex@mrabarnett.plus.com> - 2012-08-07 18:12 +0100

#26730 — Re: Q on regex

FromMRAB <regex@mrabarnett.plus.com>
Date2012-08-07 18:12 +0100
SubjectRe: Q on regex
Message-ID<mailman.3064.1344359523.4697.python-list@python.org>
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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web