语法错误与unix中的正则表达式 [英] syntax error with a regex in unix

查看:126
本文介绍了语法错误与unix中的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着找到一个匹配1到999之间任何数字的正则表达式。
当使用钩子时,我得到一个语法错误

 < 


当我不知道什么时候,使用钩子什么都没有发生。



我的正则表达式是:

  egrep ^([1-9] [0-9]?|)$ Numbers 

update:



但我怎么能让他检查我想要他检查的文件,因为知道我可以检查数字,如果我使用回声但我应该检查文件 p>

解决方案

这应该匹配1到999之间的任何数字。我添加了 {0,2} 这意味着[0-9]字符组的0到2个重复匹配。

  ^ [1- 9] [0-9] {0,2} $ 

如果您尝试匹配括号和管道字符,那么你需要转义它们:

  ^ \([1-9 ] [0-9] {0,2} \ | \)$ 


I tried find a regular expression that matches any number between 1 and 999. When is uses hooks I get a syntax error

(bash: syntax error near unexpected token `(')

and when I don't use the hooks nothing happens.

my regex is:

egrep ^([1-9][0-9]?|)$ Numbers

update:

but how can i get him to check the file i want him to check, because know i can check the numbers if i use echo but i should check the file

解决方案

This should match any number between 1 and 999. I added the {0,2} which means match between 0 and 2 repeats of the [0-9] character group.

 ^[1-9][0-9]{0,2}$

If you are trying to match the parenthesis and pipe character, then you'll need to escape them:

 ^\([1-9][0-9]{0,2}\|\)$

这篇关于语法错误与unix中的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆