2

In Java, can I split a String from left to right where the left part is an alphabet while the right part is numeric? Assuming the String is always a valid string (e.g. all string to be evaluated always starts with an alphabet and ends with a whole number/ no decimal places):

  1. L1293 = ["L", "1293"]
  2. WMG16 = ["WMG", "16"]
  3. SP9878558 = ["SP", "9878558"]
  4. Q12 = ["Q", "12"]
  5. APMZ1 = ["APMZ", "1"]

The alphabet part can be virtually range 0 or more length. I've done some tokenizing/looping each character, like checking where the first digit character will appear, and split it there, using Character.isDigit(), String.indexOf(), and so on. I'm thinking, maybe there is a one-liner for this.

Gideon
  • 1,469
  • 2
  • 26
  • 57

0 Answers0