2
Using FreeBSD 11.1:
#!/bin/sh
if printf 'abcde.fgh' | grep -iEq '^[^][$^*_-]'; then
echo "test 1 success"
else
echo "test 1 fail"
fi
echo
if printf 'abcde.fgh' | grep -iEq '^[^][.$^*_-]'; then
echo "test 2 success"
else
echo "test 2 fail"
fi
Output:
test 1 success
grep: Unmatched [ or [^
test 2 fail
But AFAICT these should give the same result. They both contain a condition on the first character (only), that it isn't one of a list of specified non-alphabetic characters. Breakdown of the regex:
^
= start of string[^...]
= match if none of these characters- Within the list,
]
must be the first character,^
must not be the first, and - must be the last. So][.^$_-
is a valid list of literal characters and the string mustn't match any of them. - To avoid confusion note that this means the
][
are literal"]"
and"["
chars in the list, not a close-and-reopen of 2 lists.
The only difference between the 2 expressions is the "."
but it's inside a list, so it should be treated as not literal .
and indeed the first char doesn't match literal "."
What am I missing? Something very obvious and simple, probably?
Ahhh. Makes sense. I wasn't looking out for other multicharacter class syntax that it might resemble, so that was way off my horizons. Thanks! – Stilez – 2018-08-07T06:08:31.623