Given a line of text with two words, such as:
给出一行包含两个单词的文本,例如:
hi hello
你好
How can I replace the first occurrence of a space with a comma, giving desired result:
如何用逗号替换第一次出现的空格,从而得到所需的结果:
hi, hello
你好
Sublime text regex ^([^\s]*)(\s)
gives:
Sublime text regex ^([^ \ s] *)(\ s)给出:
hi
hello
你好
Where the gray represents the selected area (notice it's also including the word hi
, when it should only include the first space for replacing), which if I ran find replace on, would give:
灰色表示所选区域(注意它还包括单词hi,当它应该只包括第一个替换空间时),如果我运行find replace on,则会给出:
, hello
, 你好
1 个解决方案
#1
1
You capture up to the space and include the captured content in your replacement.
您可以捕获到该空间并在您的替换中包含捕获的内容。
Find what: ^(\S*)\s
Replace with: \1,
找到:^(\ S *)\ s替换为:\ 1,
#1
1
You capture up to the space and include the captured content in your replacement.
您可以捕获到该空间并在您的替换中包含捕获的内容。
Find what: ^(\S*)\s
Replace with: \1,
找到:^(\ S *)\ s替换为:\ 1,