Bash regex for a word with some suffixes, but not one specific

I need (case insensitive) all matches of several variants of the word - except for one - including unknowns.

I want to

accept
acceptance
acceptable
accepting

... but not "acceptance." The employee used it when he meant "exception". A lot of.

Since I cannot foresee options (or typos), I need to allow things like "acceptjunk" and "acceptMacarena"

I thought I could do it with a negative look, but it did not produce the results that I need

grep -iE '(?!acception)(accept[a-zA-Z]*)[[:space:]]' file

The trick is that I can accept strings (har) containing "acception", provided that the other words match. For example, this line in order corresponds to:

Acceptance of the inevitable is acceptance.

... grep grep -v :

grep -iE '(accept)[a-zA-Z]*[[:space:]]' | grep -vi 'acception'

, . a-zA-Z, , grep -i, . , , - ... . ?

.

PS: grep, bash - awk, , ().

PPS: , https://regex101.com/ , grep.

+4
1

, GNU grep PCRE

grep -iP '(?!acception)(accept[a-z]*)[[:space:]]'


awk

awk '{ip=$0; sub(/acception/, ""); if(/accept[a-zA-Z]*[[:space:]]/) print ip}'
  • ip=$0
  • sub(/acception/, "") ,
  • if(/accept[a-zA-Z]*[[:space:]]/) print ip ,
+5

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


All Articles