0

I want to be able to split the string into substrings where characters and numbers are separate groups:

re:=regexp.MustCompile("**MAGIC HERE**")
fmt.Println(re.FindAllString("abc123def", -1))

I want to be able to get

[abc 123 def]

Any ideas?

1
  • @Wiktor this is not exactly duplicate. Even if I know the other post, I would love to know how to do this in Golang. Commented Sep 18, 2017 at 15:55

1 Answer 1

4

Try splitting on this pattern:

\d+|\D+

Code:

re:=regexp.MustCompile("\\d+|\\D+")
fmt.Println(re.FindAllString("abc123def", -1))

Output:

[abc 123 def]

Demo here:

Rextester

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.