Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a string on numbers and it substrings?

How to split a string on numbers and substrings?

Input: 34AG34A
Expected output: {"34","AG","34","A"}

I have tried with Regex.Split() function, but I can not figure out what pattern would work.

Any ideas?

like image 233
Peter Stegnar Avatar asked Sep 06 '10 08:09

Peter Stegnar


People also ask

How do I split a string into number of substrings?

Use the Split method when the substrings you want are separated by a known delimiting character (or characters). Regular expressions are useful when the string conforms to a fixed pattern. Use the IndexOf and Substring methods in conjunction when you don't want to extract all of the substrings in a string.

How can I split a string into an array of substrings?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How do you split a string into the number of substrings in Python?

When you need to split a string into substrings, you can use the split() method. In the above syntax: <string> is any valid Python string, sep is the separator that you'd like to split on.


1 Answers

The regular expression (\d+|[A-Za-z]+) will return the groups you require.

like image 184
robyaw Avatar answered Sep 22 '22 20:09

robyaw