Skip to content

Instantly share code, notes, and snippets.

@iliyaZelenko
Created August 27, 2018 19:06
Show Gist options
  • Save iliyaZelenko/77494f5e3f4d26f30fdc750d2693d336 to your computer and use it in GitHub Desktop.
Save iliyaZelenko/77494f5e3f4d26f30fdc750d2693d336 to your computer and use it in GitHub Desktop.
Find all words in text(regular expression)
function getWords (text) {
return text.match(/([^\u0000-\u0040\u005B-\u0060\u007B-\u00BF\u02B0-\u036F\u00D7\u00F7\u2000-\u2BFF])+/g)
}
// Example:
// For text: 'Есть button, h1, textarea. Мне нужно: найти самое длинное слово в-textarea! то -- что пишу в ней'.match(...)
// Result will be: ["Есть", "button", "h", "textarea", "Мне", "нужно", "найти", "самое", "длинное", "слово", "в", "textarea", "то", "что", "пишу", "в", "ней"]
// AUTOR: https://regexr.com/3b0ik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment