How to allow regex match with one character wrong

php, regex

Solution

Use `levenshtein` function instead of regex. Here are the docs.

On example `echo levenshtein("abcd","abce")` prints out: `1`.

Edit: Please also note that this function will compare strings of different lengths, so additional check could be needed. See @Vulcan's comment below.

Problem

I'm trying to figure out if there's an easy way to have a particular regex give matches that are correct except for one character. (Working in PHP if that matters). For example, for the pattern 'apples', I want to find not only occurrences of "apples" but also "appxes", "opples", "applis", etc. Is there any good way to accomplish this? Thanks in advance!

Original source