简体   繁体   中英

How to split a String at all special characters except dot?

String line="word,1.2;3.1!4.5";

What regex should I use in Split(...) to remove all special characters except dot? (I need the dot to keep double and float values)

You may try this,

string.split("[^.\\w]");

or

string.split("[^.a-zA-Z\\d]");

Add + after the character class, if you want to apply split on one or more characters.

试试这个代码

line.split("[.\w]");
(?!\\.)\\W

You can also use this.See demo.

https://regex101.com/r/cD5jK1/4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM