Currently using /[\W]+/gall characters other than the words I want are displayed.
/[\W]+/g
However, I would like to omit hyphens when they are not surrounded by spaces (i.e. when they are used as connecting words).
Examples:
var test = [ 'e-mail', // Nothing shouldn't be captured 'e-commerce is great.', // Spaces and full stop should be captured 'He - yes he - went', // Dashes and white space should be captured 'He&-you, me-him' // &-, and the whitespace should be captured while the dash in me-him should not ]
Try using ([\W]-|-[\W]|[^\w-])+
([\W]-|-[\W]|[^\w-])+
, lookaheads , . , ([\W]), , ([^\w-]), , ([\W]- -[\W]). , -, , .
[\W]
[^\w-]
[\W]-
-[\W]
Source: https://habr.com/ru/post/1606421/More articles:How to use Spring Session + Spring xml security configuration and multi-gain filter - spring-data-redisAndroid 5 Rotation Vector Sensor is not accurate - androidComparing a string with a given pattern - phpIn sql, what is the best way to store multiple ordered vectors / lists? - listHow to mix Swift and Objective-C in pod lib? - objective-cUnderstanding JS event loop - javascriptКак назначить хэш в factory девушке? - rubyИспользуйте поток данных TPL для инкапсуляции конвейера, заканчивающегося в блоке действий - c#can't change badges / colors of markers in file cabinet - javascriptLua How to tell 1 of 1.0 - doubleAll Articles