JSFiddle - React, Tailwind, and code Playground
by Lardpower
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
JavaScript
const testStrings = [
'test string 1',
'& this is & the first string',
'another 891724 9712df moisdfa',
'andanother',
'b*tch',
];
testStrings.forEach((s) => {
console.log(_.words(s), s.split(' '), s.split(/[^a-zA-Z-]+/).filter(Boolean));
});