How can I locate a comma at a certain position (e.g. third comma in the string), and replace what is between the comma and the next comma using regex?
如何在某个位置找到逗号(例如字符串中的第三个逗号),并使用正则表达式替换逗号和下一个逗号之间的内容?
1 个解决方案
#1
1
There's not much I can tell you about how to replace if I don't know what language you are using but here is the regex you need I think.
如果我不知道你正在使用什么语言,我可以告诉你如何更换,但这里是我需要的正则表达式。
example:
例:
name,surname,like long walks on the beach,phone, age
regex:
正则表达式:
^(?<name>[a-z ]+),(?<surname>[a-z ]+),(?<walks>[a-z ]+),(?<phone>[a-z ]+),(?<age>[a-z ]+)
From there you just choose what group you would like to replace in you desired language or framework.
从那里,您只需选择您想要用您想要的语言或框架替换的组。
Also you do not have to use groups I just prefer them, I find it makes it easy for me to identify what each code block represents.
此外,您不必使用我更喜欢的组,我发现它可以让我轻松识别每个代码块代表的内容。
also https://regex101.com/ is a great site to play around with you regular expressions
另外https://regex101.com/是一个很棒的网站,可以和你一起玩正则表达式
hope this helped
希望这有帮助
#1
1
There's not much I can tell you about how to replace if I don't know what language you are using but here is the regex you need I think.
如果我不知道你正在使用什么语言,我可以告诉你如何更换,但这里是我需要的正则表达式。
example:
例:
name,surname,like long walks on the beach,phone, age
regex:
正则表达式:
^(?<name>[a-z ]+),(?<surname>[a-z ]+),(?<walks>[a-z ]+),(?<phone>[a-z ]+),(?<age>[a-z ]+)
From there you just choose what group you would like to replace in you desired language or framework.
从那里,您只需选择您想要用您想要的语言或框架替换的组。
Also you do not have to use groups I just prefer them, I find it makes it easy for me to identify what each code block represents.
此外,您不必使用我更喜欢的组,我发现它可以让我轻松识别每个代码块代表的内容。
also https://regex101.com/ is a great site to play around with you regular expressions
另外https://regex101.com/是一个很棒的网站,可以和你一起玩正则表达式
hope this helped
希望这有帮助