I have two quick question with regex with grep.
what does
\?
mean? I didn't find the explanation for question mark (?
)How can I achieve
or
? for example, the phone number xxx-xxx-xxxx but the first part could 开发者_如何转开发be (xxx)
For example, there might be a digit or not between two letters, such as a1b
and ab
, how to do that?
Thanks!
?
has special meaning in a regular expression. If you want to match a literal question mark, you need to escape it - \?
If you want to match a string both with an without a particular part, you use the question mark - /^a1?b$/
will match either ab
or a1b
.
grep ".*a1\?b.*" files
精彩评论