regex failed to match using {M,N} on SunOS

↘锁芯ラ 提交于 2019-12-02 07:11:18

问题


I have the following sample file and regular expression.

testing.txt

testing                  aa
a bc de
e                        aa
ba                        Z
testing                  bb
testing                  ac

my regular expression using egrep

egrep '[ ]{2,}' testing.txt

The above regular expression attempts to find contiguous white spaces in a line. However, the result returned is empty.

the regulartion expression below works for 1 or more spaces. However that is not what I want.

egrep '[ ]+' testing.txt

回答1:


If your system is old, this help reference might be describing the issue:

Traditional egrep did not support the { metacharacter, and some egrep implementations support \{ instead, so portable scripts should avoid { in egrep patterns and should use [{] to match a literal {.

That means, that - if grep '[ ]\{2,\}' testing.txt does not work - you are better off using Perl or GNU grep to achieve what you want.

Also, egrep '[ ][ ]+' testing.txt seems to be a workaround only in the current situation, and will not scale, but it certainly will help you for the time being.



来源:https://stackoverflow.com/questions/38822261/regex-failed-to-match-using-m-n-on-sunos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!