java

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.

Related Question Split String into Array based on multiple delimiters in Java How to split a String with multiple delimiters in Java How to split a string on multiple delimiters stored in a list? How to split with multiple delimiters Split String on the basis of multiple delimiters Split a string with multiple unique delimiters Split a String by multiple delimiters in java How to split a string (based on a variety of delimiters) but without keeping whitespace? How to split string which has different values with multiple delimiters? Split string based on regex but keep delimiters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM