Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Using special characters in left part of a regex match?

by Kenosis (Priest)
on Feb 05, 2013 at 23:07 UTC ( #1017300=note: print w/ replies, xml ) Need Help??


in reply to Using special characters in left part of a regex match?

Would something like the Levenshtein edit distance assist you (the greater the value, the greater the two strings' distance)?

use strict; use warnings; use Text::LevenshteinXS qw(distance); my @var; $var[0] = "Gallia est omnis divisa in partes tres"; $var[1] = "Gallia est omnis divisa in ..."; $var[2] = "Gallia est omnis ..."; $var[3] = "Gallia"; $var[4] = "... omnis divisa in ..."; $var[5] = "Gallia est ... tres"; $var[6] = "Gallia ... partes tres"; $var[7] = "Gallia est ... partes tres"; $var[8] = "Gallia ... divisa ... tres"; $var[9] = "... tres"; $var[10] = "quattuor"; print qq{Each string's 'distance' from "$var[0]":\n\n}; for ( 0 .. $#var ) { print distance( $var[0], $var[$_] ) . " - $var[$_]\n"; }

Output:

Each string's 'distance' from "Gallia est omnis divisa in partes tres" +: 0 - Gallia est omnis divisa in partes tres 11 - Gallia est omnis divisa in ... 21 - Gallia est omnis ... 32 - Gallia 21 - ... omnis divisa in ... 22 - Gallia est ... tres 19 - Gallia ... partes tres 15 - Gallia est ... partes tres 18 - Gallia ... divisa ... tres 33 - ... tres 34 - quattuor


Comment on Re: Using special characters in left part of a regex match?
Select or Download Code
Re^2: Using special characters in left part of a regex match?
by soonix (Vicar) on Feb 06, 2013 at 20:31 UTC
    Is there a Levenshtein implementation that uses words instead of letters? That probably would be suitable to the problem at hand, although not exactly what the OP wanted.
Re^2: Using special characters in left part of a regex match?
by shamat (Novice) on Feb 06, 2013 at 20:38 UTC
    Thank you Kenosis, I was not aware of that, it may be a useful tool for further researches.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (15)
As of 2015-07-06 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls