【问题标题】:Find & Replace digit by digit and space in Sublime Text在 Sublime Text 中逐位查找和替换
【发布时间】:2014-08-12 20:24:11
【问题描述】:

我有很多数字,我想在它们之间添加空格,如下所示:

0123456789 --> 0 1 2 3 4 5 6 7 8 9

我正在尝试使用 Sublime Text 中的搜索和替换功能来执行此操作。到目前为止,我尝试使用\S 查找所有字符(只有数字,所以没关系)并使用\1\s 替换它们。但是,这会删除数字并将其替换为s。有人知道怎么做吗?

【问题讨论】:

    标签: regex replace find sublimetext3 digit


    【解决方案1】:

    您可以使用Lookahead and Lookbehind 断言的组合来执行此操作。使用Ctrl + H打开搜索和替换,启用正则表达式,输入以下内容并点击全部替换

    Find What: (?<=\d)(?=\d)
    Replace With: empty space
    

    Live Demo


    解释

    (?<=        # look behind to see if there is:
      \d        #   digits (0-9)
    )           # end of look-behind
    (?=         # look ahead to see if there is:
      \d        #   digits (0-9)
    )           # end of look-ahead
    

    【讨论】:

      【解决方案2】:

      Ctrl + H 打开搜索和替换对话框(确保单击左侧的.* 以启用正则表达式模式):

      • 搜索:(\d)(?!$)
      • 替换为:$1[space]

      正则表达式(\d)(?!$) 匹配除行尾数字之外的所有数字。

      它是这样的:

      【讨论】:

        【解决方案3】:

        您可以使用此模式 (\d)(?=\d) 并替换为 $1 Demo

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-09-10
          • 2017-08-27
          • 1970-01-01
          • 2013-07-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-01-02
          相关资源
          最近更新 更多