在字符串中查找多个空格

时间:2018-09-30 10:35:14

标签: regex sublimetext3

我正在尝试查找以“ 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)+

1 个答案:

答案 0 :(得分:1)

您可以使用

查找内容(?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\)))[^\s"]*\K\s+
替换为_

请参见regex demo

详细信息

  • (?:\G(?!\A)|jpeg\("(?=[^"]*"[^)]*600\)))-匹配
    • \G(?!\A)-上一场比赛的结束
    • |-或
    • jpeg\("(?=[^"]*"[^)]*600\))-jpeg(",后跟"以外的任何0+字符(带有[^"]*),然后是",然后是除0以外的任何0+字符),然后600)
  • [^\s"]*-匹配并消耗除空格和"之外的0+个字符
  • \K-匹配重置运算符,从匹配缓冲区中清除之前匹配的文本
  • \s+-1个以上的空格(它们将被替换)。