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

Published: 30 October 2019
on channel: 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


On this page of the site you can watch the video online Java Split on Spaces and Special Characters | Java String Split on Spaces and Special Characters with a duration of hours minute second in good quality, which was uploaded by the user Coding Trainer 30 October 2019, share the link with friends and acquaintances, this video has already been watched 616 times on youtube and it was liked by 3 viewers. Enjoy your viewing!