sed - 如何在 MacOS 上使用 sed 删除包括反斜杠在内的模式?
问题描述
我正在尝试使用 sed 删除诸如“\subsection{sometext}”之类的模式,
所以从:
Important astrophysical issues could be solved...
\subsection{ Introduction\good line}
\subsection{? apple $ fast burry }white
abc
我想:
Important astrophysical issues could be solved...
white
abc
我努力了:
sed -E -i '' 's/\\(section|subsection|subsubsection)\{([^\}]+)\}//g' test.tex
但结果是:
Important astrophysical issues could be solved...
\subsection{ Introduction\good line}
white
abc
似乎包含反斜杠的文本不匹配。我使用 MacOS。
解决方案
}
inside[]
不需要转义,所以:
's/\\(section|subsection|subsubsection)\{([^}]+)\}//g'
简单有效。
你可以看到规则re_format(7)
:
... 除了这些和一些使用 `[' 的组合(参见下一段)之外,所有其他特殊字符,包括 `\',在括号表达式中都失去了它们的特殊意义。
推荐阅读
- node.js - Node.js 与 MongoDB 的连接
- javascript - 引导导航栏:登录时注销按钮和用户名的位置
- algorithm - 分解字符串以形成有效的表达式
- java - SpringBoot 2 - 监控数据库连接
- c# - 登录时会话过期错误
- python - 使用张量、lambda 和 python 变量绑定自定义学习率衰减
- css - 如何将 sass 和 scss 与 webpack 混合使用?
- react-native - React Native 的导航库
- facet-wrap - 如何在 iNext 函数中更改 facet.var 的字母顺序?
- exoplayer - 如何在 google IO18 audio App demo 中添加播放器控制 ui