Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Q on regex

Reply
Thread Tools

Re: Q on regex

 
 
MRAB
Guest
Posts: n/a
 
      08-07-2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
String Pattern Matching: regex and Python regex documentation Xah Lee Java 1 09-22-2006 07:11 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments