Thunder
Thunder

Reputation: 10986

Is there a regular expression for like

I am trying to use string matching in a winforms application .I would like to match the patterns such as bank will be matched by benk or bamk etc so i cannot use

b.nk because then it will not match bamk , it is to give the user a nearest possible option even if the user types wrongly eg in the spelling correction in most applications (but its not for spelling correction)

some other examples : 
Valid list : possible ,bank, easy,thanks
posible matches possible 
benk matches bank
easi matches easy 
eassy matches easy 
Thaks matches Thanks

Upvotes: 1

Views: 157

Answers (1)

jerry_sjtu
jerry_sjtu

Reputation: 5456

You need the edit distance not regular expression. Most commonly, the edit operations allowed for this purpose are

  1. insert a character
  2. delete a character
  3. replace a character with another character.

The edit distance is the number of operations needed to change a string to another string. The string with small distance is most likely what you want. For example benk will has small edit distance with bank.

Upvotes: 2

Related Questions