Home > OS >  Split string before the number out of text with mix number and string in Javascript
Split string before the number out of text with mix number and string in Javascript

Time:09-10

I have some string like this

"ABC17" , "ABCDE16", "AB17a",  "ABCDER10b" 

I want to split the string that goes in front of the number out so the result is like

"17" , "16", "17a", "10b"

Is there a way to do this?

I have tried

string.split(/(\d )/)[1]

but this only takes all of the letters out of the string. I only want to take the letter in front of the number out and keep the number and letter after the number, such as 10b.

CodePudding user response:

in a list you should be able to do this

var x = ["ABC17" , "ABCDE16", "AB17a",  "ABCDER10b"]
x.forEach(y=>{console.log(y.replace(/^\D*/, ''))})

CodePudding user response:

You can use string.split(/^\D*//)[1]

  • Related