I have string like fullData1 upto fullData10 in this i need to separate out the integers and text part. how do I do it using javascript.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Split your string into an array by integer:
myArray = datastring.split(/([0-9]+)/)Then the first element of
myArraywill be something likefullDataand the second will be some numbers such as1or10.If your string was
fullData10foothen you would have an array['fullData', 10, 'foo']You could also:
.split(/(?=\d+)/)which will yield["fullData", "1", "0"].split(/(\d+)/)which will yield["fullData", "10", ""]Additionally
.filter(Boolean)to get rid of any empty strings ("")