John
John

Reputation: 61

split string while keeping separators

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

Upvotes: 1

Views: 93

Answers (1)

simon_xia
simon_xia

Reputation: 2544

use FindAllString

  regexp.MustCompile(`[-+\?=]?([0-9]|x)`).FindAllString("x+5-3+x=6+x-2", -1)

Upvotes: 1

Related Questions