Fuzzy match by regular expression

user1902849

How to do a "fuzzy search" by regular expression?

For example, the text "hp laptop" might be a fuzzy match for any of:

xxx hp laptop
hp xxx laptop
laptop xxxxx hp
Bohemian

Use look-aheads for each word:

(?=.*\bhp\b)(?=.*\blaptop\b).*

\b means "word boundary", so "bhp" and "laptops" won't match.

See live demo.

A look-ahead, which has the form (?=...), asserts (but doesn't consume) that the input matches the regex (the dots ... in this example). Because it doesn't consume input, the pointer doesn't advance when they are evaluated, so you can have multiple look-aheads at the same point.

Read this for a far more detailed explanation.

Use as many of these look-aheads as you have words in your search query.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related