开发者

grep with regex

I have two quick question with regex with grep.

  1. what does \? mean? I didn't find the explanation for question mark (?)

  2. 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜