如何用逗号替换 space 的最后一个实例
How replace last instance of space with comma
我有一个文本文件,想把最后的space换成逗号,方便数据导入和处理。
我的文本文件包含以下示例行:
Some text 123 here and then 44.99
more text 789 is 33.75
我想得到的结果:
Some text 123 here and then,44.99
more text 789 is,33.75
您可以使用以下正则表达式替换:
Find what: \h+(\S+)$
Replace with: ,
参见regex demo。
详情
\h+
- 任何水平空格重复 1 次或多次 (+
) (\h
)
(\S+)
- 捕获第 1 组:除空格以外的任何一个或多个字符 (\S
)
$
- 一行结束。
,
替换用逗号和第 1 组的内容替换匹配的文本。
我有一个文本文件,想把最后的space换成逗号,方便数据导入和处理。
我的文本文件包含以下示例行:
Some text 123 here and then 44.99
more text 789 is 33.75
我想得到的结果:
Some text 123 here and then,44.99
more text 789 is,33.75
您可以使用以下正则表达式替换:
Find what: \h+(\S+)$
Replace with: ,
参见regex demo。
详情
\h+
- 任何水平空格重复 1 次或多次 (+
) (\h
)(\S+)
- 捕获第 1 组:除空格以外的任何一个或多个字符 (\S
)$
- 一行结束。
,
替换用逗号和第 1 组的内容替换匹配的文本。