在Sublime Text中逐位查找和替换数字

Zer*_*ero 3 regex replace find digit sublimetext3

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

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

我正在尝试使用Sublime Text中的搜索和替换功能.到目前为止我所尝试的是使用\S查找所有字符(只有数字,所以无关紧要)并\1\s替换它们.但是,这会删除数字并替换它们s.有人知道怎么做这个吗?

hwn*_*wnd 5

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

Find What: (?<=\d)(?=\d)
Replace With: empty space
Run Code Online (Sandbox Code Playgroud)

现场演示


说明:

(?<=        # 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
Run Code Online (Sandbox Code Playgroud)


Ama*_*ali 4

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

  • 搜索:(\d)(?!$)
  • 用。。。来代替:$1[space]

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

它看起来是这样的:

在此输入图像描述