匹配SED零个或多个字符 [英] Matching zero or more characters in sed

查看:1044
本文介绍了匹配SED零个或多个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在练习使用SED一些命令的时候我用以下命令的输出困惑:

I was practicing some commands using sed when I was confused by the output of the following command:

echo 'first:second' | sed 's_[^:]*_(&)_g'

我的问题是:为什么会这样命令只换字符串第一,第二在括号

My question is: Why would this command only wrap the string "first" and "second" in parentheses?

应该不是冒号太,因为我指定的包装或多个非冒号在我的正则表达式条件?

Shouldn't the colon be wrapped too since I specified "zero or more non-colons" in my regex condition?

请澄清一下。

推荐答案

您使用

[^:]

这将搜索所有的字符,除了
让你体验什么是正常的行为举止。

which searches all characters except :. So what you experience is the normal comportment.

这篇关于匹配SED零个或多个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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