英文:
split string while keeping separators
问题
你好,以下是翻译好的内容:
有没有办法在保留分隔符的情况下拆分字符串 x+5-3+x=6+x-2?我尝试使用正则表达式的 [\+\-] 进行拆分,但结果是 x, 5, 3, ...,而我需要的是 x, +5, -3, +x。在Java中使用 (?=[-+]) 也不起作用。
谢谢。
英文:
any way I can split this string x+5-3+x=6+x-2 while keeping the separators, I tried regex split on [\+\-] but this gives me, x, 5, 3, ... and I need x, +5, -3, +x using (?=[-+]) as in Java doesn't work.
Thanks
答案1
得分: 1
使用FindAllString函数
regexp.MustCompile([-+\?=]?([0-9]|x)).FindAllString("x+5-3+x=6+x-2", -1)
英文:
use FindAllString
regexp.MustCompile(`[-+\?=]?([0-9]|x)`).FindAllString("x+5-3+x=6+x-2", -1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论