Regex To find misspelled words

I am trying to combine words with two missing letters with a regular expression. For example, if the word of interest is "hello", I want to match the following lines:

hi hell HELO hllo ELLO high-energy laser VEO Elo LLO

Can I use regex h? e? l? l? o? to match these, but it will also match 0, 1, and 2 letter strings. How can I require a match to last 3-5 characters?

Thanks for the help.

+6
source share
3 answers

You can use the look to check 3-5 of these characters:

(?=[hello]{3,5})h?e?l?l?o? 

Note that this will find a match as in a line like help , since help contains hel . If you want to use stp, you can check word boundaries or line endings depending on your situation. If you want a match for the ends, add ^ to the beginning and $ to the end. If you want to check word boundaries, add \b to both ends.

+6
source

I think this will work ((?=.{3,})h?e?l?l?o?) - your regular expression with the addition of "at least 3 characters."

You probably want this to match whole words (not the beginning of something like "hellow"), so add \b to the beginning and end: \b((?=.{3,})h?e?l?l?o?)\b

+3
source

You can try something like this:

 [hello]{3,5} 
+1
source

Source: https://habr.com/ru/post/893743/


All Articles