const regex = /[a-zа-яёіїє0-9][a-zа-яёіїє0-9'-_]+[a-zа-яёіїє0-9]|[a-zа-яёіїє0-9]+/ig;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[a-zа-яёіїє0-9][a-zа-яёіїє0-9\'-_]+[a-zа-яёіїє0-9]|[a-zа-яёіїє0-9]+', 'ig')
const str = `asdf a as
asdf, asdf asdf ,asdf asdf , asdf
,,, asdf asdfasdf,asdf
(asdfasdf)
456456 1 12
фываФЫВА
фываё
фіва - фівафві
фвіа фівоажлдіва
ііфваів'фіваів 'h'a'a'a' ' asdf' 'asdf
ііфваів-фіваів -a-a-a-a- - asdf- -asdf
jkjkhljkh_hj _B_B_B_B_B_B_ _ hjkl_ _hjhjl
8885 4566
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions