regex - 正则表达式替换

标签 regex linux sed gnu

我正在尝试对典型的 g++ 命令行进行一些修改。我正在尝试构建一个寻找 -o object_filename.o 的正则表达式结构体。为了测试我的匹配模式,我在 sed 中启动它,并用一个空字符串作为替代。但它没有按预期工作,因为它没有删除任何内容......

$echo "-o toto.o" | sed 's/-o [^ ]+//'<br/> -o toto.o

最佳答案

您缺少一个 -E 标志; without it, + is not treated as a regex meta-character :

$echo "-o toto.o" | sed -E 's/-o [^ ]+//'

如预期的那样,上面的代码产生了一个空输出。

关于regex - 正则表达式替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13530182/

相关文章:

regex - Delphi VCL提供正则表达式库吗?

regex - 使用正则表达式从 clojure 集合中提取字符串

linux - PostgreSQL 服务器的 Yocto 配方

sed - 使用 sed 删除文件的行 - 意外行为

c# - 将 C# 正则表达式转换为 javascript

Angular Validation : Input should either contain Latin or Georgian characters, 但不能同时使用

linux - 从 unzip -l 中获取 N 行

java - 如何让Jenkins查找作业中指定的shell脚本

linux - 转换列模式

mysql - 将列名转换为大写的 MYSQL 脚本