I want to split string based on multiple delimiters
I have tried "property == Test property1 != Test1".split("[==!=]")
and "property == Test property1 != Test1".split("['==''!=']")
but it is splitting based on '='
not '=='.
please help me out
Since split
takes a regex , you can use |
( OR operator ):
String[] splitted = myString.split("==|!=");
perhaps I'm not understanding your question but why aren't you just doing "property == Test".split("==")
? If your intention is to use regex then you can group your matches and separate them with an |
(or) as in "property == Test".split("(==)|(!=)")
Write a multi-character regex alternative using | alternative operator, not a [] character specifier. Character specifiers specify how to match a single character only.
String[] results = input.split( "(==|!=)");
theStringYouWantToSplt.split("==|!=");
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.