正则表达式在 SunOS 上使用 {M,N} 匹配失败 [英] regex failed to match using {M,N} on SunOS

查看:22
本文介绍了正则表达式在 SunOS 上使用 {M,N} 匹配失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例文件和正则表达式.

I have the following sample file and regular expression.

测试.txt

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

我使用 egrep 的正则表达式

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.

下面的正则表达式适用于 1 个或多个空格.然而这不是我想要的.

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

egrep '[ ]+' testing.txt

推荐答案

如果你的系统很旧,此帮助参考 可能正在描述问题:

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

传统 egrep 不支持 { 元字符,而一些 egrep 实现支持 {,所以可移植脚本应该避免 { 在 egrep 模式中,应该使用 [{] 来匹配文字 {.

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 {.

这意味着 - 如果 grep '[ ]{2,}' testing.txt 不起作用 - 你最好使用 Perl 或 GNU grep 来实现你想要的.

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.

另外,egrep '[ ][ ]+' testing.txt 似乎只是在当前情况下的一种解决方法,并且不会扩展,但它暂时肯定会对您有所帮助.

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.

这篇关于正则表达式在 SunOS 上使用 {M,N} 匹配失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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