开发者

grep with regex

开发者 https://www.devze.com 2022-12-20 11:29 出处:网络
I have two quick question with regex with grep. what does \\? mean? I didn\'t find the explanation for question mark (?)

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

精彩评论

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