1

If you have the string a = "Super rich rush to buy superyachts" and you have the string b = "ruush to buyy".

My question is: Is it possible to use regex to make a confirmation if almost all word from the string "a" is the same from the string "b"? If yes, how?

KLN
  • 413
  • 3
  • 8
  • 1
    "almost" is subjective - regex isn't very good at being subjective. You're likely looking for something like the [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) between the strings being below some threshold, rather than a regular expression. – Preston Guillot Mar 02 '16 at 21:51
  • No, that's not really what regex is for. – Blorgbeard Mar 02 '16 at 21:51
  • I think you're going to have to use a spell-checking library. Examples here: http://stackoverflow.com/questions/453611/what-is-the-best-spell-checking-library-for-c – Steve Danner Mar 02 '16 at 21:52
  • 1
    see if you can write out a precise definition of 'almost the same'. If you can then write the code that does that – pm100 Mar 02 '16 at 21:53
  • Might be worth reading up on the Edit Distance algorithm. – John Paul Mar 02 '16 at 21:55
  • If you need strictly regex answer - NO. For more practical answer see linked duplicate http://stackoverflow.com/questions/9453731/how-to-calculate-distance-similarity-measure-of-given-2-strings – Alexei Levenkov Mar 02 '16 at 21:57

1 Answers1

1

I'm not sure about using only regexes, but one algorithm often used for this sort of "fuzzy matching" is Levenshtein distance.

There are many existing C# implementations out there. One nice one is Google's Diff-match-patch

awkoren
  • 26
  • 2