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

Publicado em: 30 Outubro 2019
no canal de: Coding Trainer
616
3

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

Just use:

String[] terms = input.split("[\\s@&.?$+-]+");

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.

SUBSCRIBE:-   / rajasekharreddybusireddy  
subscribe:-   / @codingtrainer  
1. My Laptop :-https://ekaro.in/enkr2020012239511165
2.My MiC :- https://ekaro.in/enkr2020020239733045
3. BOYA Mic :-https://ekaro.in/enkr2020020239733099
4. Sony WH-1000XM3 :-https://ekaro.in/enkr2020020239733183
5. Boat 400 :-https://ekaro.in/enkr2020020239733208
6.Dell wireless keyboard mouse:-https://ekaro.in/enkr2020020239733368
7. Logitech wireless keyboard :-https://ekaro.in/enkr2020020239733394
8. Bluetooth speaker:-https://ekaro.in/enkr2020020239733444
9. Tripod :-https://ekaro.in/enkr2020020239733836
10. Blue yetti mic :-https://ekaro.in/enkr2020020239733862
11. Induction stove:-https://ekaro.in/enkr2020020239733942
12. Induction bowls:-https://ekaro.in/enkr2020020239733967
13. Phillips bluetooth speaker:-https://ekaro.in/enkr2020020239733998
14. OnePlus Tv :-https://ekaro.in/enkr2020020239733238
15. Mi Tv 4k :-https://ekaro.in/enkr2020020239733282
16. Mi 4a Tv :-https://ekaro.in/enkr2020020239733774


Nesta página do site você pode assistir ao vídeo on-line Java Split on Spaces and Special Characters | Java String Split on Spaces and Special Characters duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Coding Trainer 30 Outubro 2019, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 616 vezes e gostou 3 espectadores. Boa visualização!