regex - 在字符串中查找多个空格
问题描述
我试图在以“jpeg”开头并以 600 结尾定义的字符串中查找所有空格),以便用“_”替换它们,但是如何捕获字符串中的所有 \s?
我正在使用崇高的文本编辑器/记事本++
我试过了:
^jpeg.*(\s).*600\)$
感谢您的帮助正在编辑的文本示例:
# CHART: Share of persons living at risk of poverty or social exclusion ====
df <- S3R0004_M3080242 %>%
mutate(LAIKOTARPIS=parse_date_time(LAIKOTARPIS, "y"))
jpeg("./figures/Share of persons living at risk of poverty or social exclusion.jpeg", width = 9, height = 6, units = 'in', res = 600)
ggplot(data = df, aes(x=LAIKOTARPIS, y=obsValue)+
解决方案
您可以使用
查找内容: (?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\)))[^\s"]*\K\s+
替换为:_
请参阅正则表达式演示。
细节
(?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\)))
- 匹配任一\G(?!\A)
- 上一场比赛的结束|
- 或者jpeg\("(?=[^"]*"[^)]*600\))
-jpeg("
后跟除"
(with[^"]*
) 之外的任何 0+ 字符,然后是除and"
之外的任何 0+ 字符)
600)
[^\s"]*
- 匹配并消耗 0+ 字符而不是空格和"
\K
- 匹配重置运算符,之前匹配的文本从匹配缓冲区中清除\s+
- 1+ 个空格(它们将被替换)。
推荐阅读
- machine-learning - 有没有人可以帮助我找到准确的数据集?
- dart - 在 dart 中定义事件处理程序
- python - 使用 rdd.map() 对某些行多次调用的函数映射到 RDD
- vb.net - 将行添加到 DataGridView 控件会导致崩溃,但仅在第二次尝试时
- reactjs - 我如何构建这个 React Native Section List 实现
- powershell - 在 docker 中运行 powershell 时,获取选择不被识别为内部或外部命令
- ios - 解除分配 AVPlayer/AVPlayerItem 的问题
- .net - ICorProfilerCallback2:无法区分已处理和未处理的异常与异常事件
- google-sheets - 如何复制和复制带有脚本的绘图
- javascript - 切换时如何使响应式导航栏中的汉堡菜单过渡平滑?