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!
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.
Your regex string:
[A-z]pples|A[A-z]ples|Ap[A-z]les|Appl[A-z]es|Appl[A-z]s|Apple[A-z]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With