grep(1) uses POSIX Basic Regular Expressions by default and POSIX Extended Regular Expressions when used with the -E option.
In POSIX regular expressions, non-special characters have undefined behavior when escaping, for example. \s , and there is no syntax for non-greedy matching, for example. +? . In addition, the BRE operators + and | not available, and brackets must be escaped to perform grouping.
the POSIX character classes [[:space:]] and [[:alnum:]_] are portable alternatives to \s and \w respectively.
Excluding the next matching character from a repetition can be used to emulate an undesired match, for example. [^*]+?\w*: equivalent to [^*[:alnum:]_:]+[[:alnum:]_]*:
This regular expression can be represented as multiple BREs:
grep -e '^[[:space:]]*\*[[:space:]]\{1,\}\[ \][^*[:alnum:]_+]\{1,\}[[:alnum:]_]*:[^*]\{1,\}[[:digit:]]$' \ -e '[^*]\{1,\}\.com\.au$' file1
or ERE:
grep -E '^[[:space:]]*\*[[:space:]]*\[ \][^*[:alnum:]_:]+[[:alnum:]_]*:[^*]+[[:digit:]]$|[^*]+\.com\.au$' \ file1
Note that the GNU grep(1) implementation allows for both short character classes ( \s and \w ) and unwanted repetition ( +? ) As non-portable extensions.
kdhp
source share