one, single-character said:
1. Specific characters: a specific character.
' 1 '
' A '
' \. '
2. Single character within range: single character []
[0-9]
[259]
[A-z]
[ABC]
[A-z]
[ABC]
[A-za-z]
[,:/]
[.]
character inversion:
[^0-9]
[^123]
3. Any character:
. The character has a specific meaning
grep '. '/etc/passwd
4. Boundary character: Kinsoku character
head: grep ' ^root '/etc/passwd
tail: grep ' false$ '/etc/passwd
blank line: ^$
5, meta-character:
Word class Character: [a-za-z0-9_]= case letter + number + underscore = ' \w '
grep ' \w '/etc/passwd
non-word type characters: ' \w '
grep ' \w '/etc/passwd
word delimiter: ' \b '
grep ' \bx\b '/etc/passwd means that both front and back of X are non-word letters
string representation: The combination of a string of characters
' Root '
' + '
' M.. C ' one of the individual. Represents a character
' [a-z][a-z] '
' \b[0-9][0-9]\b '
repeat: * +?
*: Indicates 0 or more occurrences of the preceding character or expression
+: Represents 1 or more occurrences of the preceding character or expression
? : represents 0 or 1 times the preceding character or expression
{m,n}: Repeat a specific number of times: M~n
grep ' se* '/etc/passwd-->s se see ....
grep ' se\+ '/etc/passwd-->se see seee ...
grep ' se\? '/etc/passwd-->s se
grep ' \ (se\) * '/etc/passwd--empty line other line se sese ....
grep ' \ (se\) \+ '/etc/passwd-->se sese Sesese ...
grep ' \ (se\) \? '/etc/passwd--empty line other lines se
Logic: |
three, any string:. *
string starting with ^r.* R
grep ' ^r.* '/etc/passwd
Compare the differences:
grep ' M. C '/etc/passwd
grep ' m.*c '/etc/passwd
Linux Regular expressions