上QQ阅读APP看书,第一时间看更新
Zero or one
The zero or one operator (?) matches occurrences of the preceding character zero or one time. For example, we use ? to mark the e as an optional character to match the Jean or Jan string, as follows:
$ echo -e "Jean\nJan\nJeean" | awk '/Je?an/'
The output on execution of the preceding code is as follows:
Jean
Jan
A summary of the unary operator for repetition is as follows:
Pattern |
Matches |
A? |
Matches the single A or null string |
AB?C |
Matches AC or ABC |