how to split string in java with multiple delimiters code example

Example 1: java array split by multiple ways

public class split_demo {
 
       public static void main (String[] args)
 
    {
 
              String str_split="split method.It is cool - (Hello-World)";
 
        for (String str_complex : str_split.split("\\s|,|\\.|-")) {
 
            System.out.println(str_complex);
 
        }
 
    }
 
}

Example 2: splitting text with several condition in java

Pattern pattern = Pattern.compile("(\\w+)([<=>]+)(\\w+)");
    Matcher matcher = pattern.matcher("var1>=ar2b");

    if(matcher.find()){
        System.out.println(matcher.group(1));
        System.out.println(matcher.group(2));
        System.out.println(matcher.group(3));
    }

Tags:

Java Example