I feel like this regex pattern should work but it doesn't

Solution 1:

The (a..e.)([a-zA-Z]) pattern looks for an a, after which there must be any two chars (other than line break chars), then an e letter, and then any single char other than line break chars. This pattern neither guarantees you match a whole word, nor that the chars matched with . will be letters.

/(a..e.)([a-zA-Z])/gi is not equal to /(a..e)([a-zA-Z])/gi as they match and consume different strings. Since there is no . after e, the second pattern matches fewer chars, not allowing any single char other than line break chars after e letter before any single letter (the last pattern part).

To match words starting with the a letter, followed with two more letters, then an e letter, and then one more letter you can use

/\ba[a-z]{2}e[a-z]\b/gi

See the regex demo. Details:

  • /gi - match all occurrences (g) in a case insensitive way (i)
  • \b - matches a word boundary
  • a - a / A
  • [a-z]{2} - two ASCII letters
  • e - an e letter
  • [a-z] - any ASCII letter
  • \b - matches a word boundary.