Answer the question
In order to leave comments, you need to log in
How to get numbers and words from a string?
There is a string from which you need to get numbers and words separately. Here is my solution, but unfortunately I can’t understand why the text remains, if it is clear that the regular expression is for numbers:
let someSrt = "954 432 534 test abc test test test abc test test abc ";
let stringNumber= someSrt.replace(/[0-9]/g, '');
console.log(stringNumber);
let stringText= someSrt.replace(/\D/g, '');
console.log(stringText);
Answer the question
In order to leave comments, you need to log in
const someSrt = "954 432 534 test abc test test test abc test test abc ";
const words = someSrt.match(/([a-zA-Z]+)/g);
const numbers = someSrt.match(/(\d+)/g);
console.log(words); // ["test", "abc", "test", "test", "test", "abc", "test", "test", "abc"]
console.log(numbers); // ["954", "432", "534"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question