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

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

问题描述

我尝试找到匹配 1 到 999 之间任意数字的正则表达式.什么时候使用钩子我得到一个语法错误

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.

我的正则表达式是:

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

更新:

但是我怎样才能让他检查我想让他检查的文件,因为我知道如果我使用 echo 我可以检查数字但我应该检查文件

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

推荐答案

这应该匹配 1 到 999 之间的任何数字.我添加了 {0,2} 表示匹配 0 到 2 次重复[0-9] 字符组的.

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天全站免登陆