nfn
nfn

Reputation: 633

regular expression for words with 8 or 7 characters

I'm looking for a regular expression that matches words with 8 or 7 characters and includes (ea). this is what I've got so far:

[\w*(ea)\w*]{7,8}

the problem is it also accepts the first 8 characters of "bbeabbbbbbb" but I dont want that.

Upvotes: 0

Views: 290

Answers (1)

Liju
Liju

Reputation: 2313

when inside charset [], brackets (,) loses its special meaning and matched literally. that's why you are getting wrong results. Try below regex.

(?=(?=(?<!\w)\w*\(ea\))[\w()]{7,8}(?:\s|$))[\w()]{7,8}

Demo in regex101.com

Upvotes: 1

Related Questions