-1

I know that there's probably a RegEx to use with string.split but I can't figure it out or find the answer.

Say I have a string where each alphabetic character is prefaced by a number:

2A3B12C, for example. How do I split this into an array of ["2A", "3B", "12C"] or failing that, at least get ["2", "A", "3", "B", "12", "C"]

thedodus
  • 9
  • 4
  • Instead of using split you can use match with something like /([0-9]+[A-Z]+)/ – NickSlash Sep 13 '20 at 22:36
  • I was able to use match with (/[0-9]+ | [a-z]+/gi) and got exactly the result I wanted. Thanks for pointing me in that direction! – thedodus Sep 14 '20 at 00:58

1 Answers1

-1

Char to integer is not that hard to write, so why not just parse it char by char: int value=0, digits=0, string="", value = value* 10 + digit - '0'; digits++; When you run out of digits, you collect letters String=string + letter;, and when you run out of letters, you send the integer and string to an answer container, reset your controls.