javascript: get the normalized from two slightly different strings -
I have an equal number of slashes and the same letter in each case is always a letter and a square bracket indicating the index .
var first = "/ a / b [1] / c / d [3] / e [1] / f" var second = "/ a / b [1] / c / D [4] / E / F "
I hope the output should be
result =" / a / b [1] / c / D / E / F "
This is what came with me, but it is probably a better way of doing it as it gives the / a / b / c / d / E / f
which I did not want
first first = "/ a / b [1] / c / d [3] / e [1] / f" Split ("/"); Var seconds = "/a/b[1]/c/d[4]/e/f".split("/"); (Var i = 0; i & lt; first.length; i ++) {first match = first [i] .mail (/ \ [[[0-9] +) \] / g); Second match = seconds [i] .mail (/ \ [[[0- 9] +) \] / g); If (first match! = Second match) {First [I] = First [i] .replace (/ \ [[[0-9] +) \] / g, '') // Get rid of class bracket. }} First.join ("/");
I have solved it, it is a node project but main file dependency is less Is portable.
Use the dynamic programming algorithm to calculate the Levenshtein distance, and use the transform to generate the regex. Subscriptions become wildcards, are included or become alternate letters.
var Levenshtein = Required ('levenshtein-conversion)'; Var Lev = new Levenshatine (str1, str2); Console.log (lev.regex ());
Comments
Post a Comment