What is the difference between
[-+]. It seems to me doing the same thing. And what does
Or I tried
awk '/[^-]/' contries
The text refers to the fact that to match a dash,
-, in a bracketed expression,
[...], the dash must occur first or last in the
[...] (or just after an initial
^, as in
[^-] which matches any single character that is not a dash).
There is no difference between
[-+]. Both matches either a
+ or a
[A-Za-z-]+ would match multiple (more than zero, due to the
+ after the
[...]) ASCII characters from
Z and from
z and dashes. The dash could also be put first as in
Note that the internal two dashes in this expression denotes ranges whereas the last dash (or first in
[-A-Za-z]+) denotes a literal dash character .
[...] modifies the expression so that it matches one or more characters from within the
[...]. Without the
+, the expression would match exactly one character, and not a word with optional dashes.
The second screenshot shows that you are matching
[Y-Zy-z-]+ against some data.
You get the same result for both patterns since that's the only line that contains one or more character from the set
YZyz-. The character that matches is the
- character in the substring
Then you tried with
[^-]. This matches on all lines, as all lines contains some character that is not a