Comments

Lenry Kabua year ago

const solve = (strArg) => {
  return strArg.match(/\w+/gi);
};

Removes all non alphabet chars

Anurag Arwalkara year ago

const solve = (strArg) => {
  const newStr = strArg.replace(/[^a-zA-Z ]/g, "");
  return newStr.split(" ").filter((i) => i);
};

Gorgeous Cottona year ago

const solve = (strArg) => strArg.split(" ")
    .map(char => char.replace(/[^0-9a-z]/gi, ''))
    .filter(char => !!char);

Avinash DV2 years ago

const solve = (strArg) => { let wordArr = strArg.split(' '); let res = []; for(let el of wordArr) { res.push(el.replace(/[^\w]/g, '')); } return res.filter(el => el!== '') };

Ali Sequeira2 years ago

const solve = (strArg) => {
   return strArg.replace(/[^\w\s]/gi, '').split(' ').filter(el => el !== '');
};

Sarthak Joshi2 years ago

const solve = (strArg) => { return strArg .replace(/[^\w]/g, " ") .split(' ') .filter(space => space.trim() !== '') };

Mac Villegas2 years ago

const solve = (strArg) => { return strArg.split(/\W|\s+/g).filter(item => item !== "") };

Bryan Guilas2 years ago

Solution without using RegEx.


const solve = (str) => {
  let chars = [...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '];
  let letter = str.split('');
  let arr = [];
  for (let el of letter) {
      if(chars.includes(el)) {
        arr.push(el)
      }
  }
  return arr.join('').split(' ').filter(space => space.trim() !== '');
};

Coordinator proactive2 years ago

const solve = (strArg) => {
  return strArg.match(/\w+/g);
};

Ameliorated Tugrik2 years ago

RegExp is a powerful and succinct tool! For those participants who are looking for a course I recommend that you watch Mastering Regular Expressions in JavaScript by Steven Hancock. Believe me or not but the syntax seems to be complex or wierd. Once you pass the course - an expression like this one would be a piece of cake.

const solve = (str) => str.match(/\b\w+\b/g);

Samuel Egwurube2 years ago

The right answer

const solve = (strArg) => {
 return  strArg.split(' ').map(e => e.replace(/[^A-z^0-9]/g, "")).filter(x=> x!= '')
};


Reuven Naor2 years ago

const solve = (a) => a.split(/[^A-z^0-9]/g).filter((i) => i !== '')

redundant District3 years ago

const solve = (strArg) => { const str = strArg.replace(/[^a-zA-Z ]/g, "").split(" "); return str.filter(n => n) };

Savings Account Ergonomic3 years ago

return strArg.match(/[A-Za-z0-9]+/g);