Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex for replacing spaces, comma, dot, semicolon, line change/new

I need to be able to take a string like this one '234; sdfghj.;34567; 45678';df950' and remove all spaces, commas, dots, semicolons, line changes/new lines to get an array like this ['234','sdfghj','34567','45678','df950']

But after that I also need to remove all none numeric characters and get this['234', '34567','45678','950']

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

const str = "234; sdfghj.;34567; 45678';df950;dfg234j98"
const alphanum = /(\w+)/g;
const result = str.match(alphanum).map(v => v.replace(/[a-zA-Z]/g, '')).filter(v => v)
console.log(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading