Java Split on Spaces and Special Characters | Java String Split on Spaces and Special Characters

preview_player
Показать описание
Java Split on Spaces and Special Characters | Java String Split on Spaces and Special Characters

Just use:

You can put a short-hand character class inside a character class (note the \s), and most meta-character loses their meaning inside a character class, except for [, ], -, &, \. However, & is meaningful only when comes in pair &&, and - is treated as literal character if put at the beginning or the end of the character class.

Other languages may have different rules for parsing the pattern, but the rule about - applies for most of the engines.

As @Sean Patrick Floyd mentioned in his answer, the important thing boils down to defining what constitute a word. \w in Java is equivalent to [a-zA-Z0-9_] (English letters upper and lower case, digits and underscore), and therefore, \W consists of all other characters. If you want to consider Unicode letters and digits, you may want to look at Unicode character classes.

Рекомендации по теме