Separate a string before a number

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

01-Oct-17 10:30
Hi all! I'm a complete noob, learning JavaScript (didn't specify this in the title, sorry) and I'd appreciate some help. Is there a way I can turn a string that contains numbers, letters, and spaces into an array, or simply slice it into different strings, but do it before the number? For example, if I have such a string "sdfls jfsdkfjh3 58sklf039 5857dfkkjhksjf h", I'd like to "pick out" the numbers only, and get an array of strings with numbers separated from the rest. I realize I can use regular expressions to pick out only numbers, but that just gives me an array of numbers, without everything else.

Thank you!

[Edited by couriousScript on 01-Oct-17 10:31]
08-Oct-17 16:11

var strA= "sdfls jfsdkfjh3 58sklf039 5857dfkkjhksjf h";
var strB = strA.split(/(\d+)/);

will get you this: sdfls jfsdkfjh,3, ,58,sklf,039, ,5857,dfkkjhksjf h

So long, and thanks for all the fish.

New posts
Old posts

Follow Elated