[英]Replace first occurrence of the “,” in the string with regex
I have a issue with regex pattern. 我对正则表达式模式有疑问。 It replace not only "," but also all characters that are before. 它不仅替换“,”,而且替换之前的所有字符。
I would like to replace first occurrence of the "," to ".": 我想将“,”的第一次出现替换为“。”:
"1,,000.23" -> "1.,000.23"
This pattern I am using now : 我现在使用的这种模式:
^(.*?),
Result that I receive is : 我收到的结果是:
"1,,000.23" -> ".,000.23"
Expected result : 预期结果 :
"1,,000.23" -> "1.,000.23"
Use ^(.*?),
and replace it with $1.
使用^(.*?),
并将其替换为$1.
. 。 This means: 这意味着:
group as less as possible things from line start till first , into group 1
then match a `,`
and replace it with the captured text of group 1 `$1` and a dot `.`
See: https://regexr.com/3kjdq 请参阅: https : //regexr.com/3kjdq
Copy the capture group to the result. 将捕获组复制到结果。 Replace 更换
^(.*?),
with 与
$1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.