user2251725 user2251725 - 26 days ago 7
Java Question

How split a string using regex pattern

How split a [0] like words from string using regex pattern.0 can replace any integer number.
I used regex pattern,

private static final String REGEX = "[\\d]";


But it returns string with [.

Spliting Code

Pattern p=Pattern.compile(REGEX);
String items[] = p.split(lure_value_save[0]);

Answer

You have to escape the brackets:

String REGEX = "\\[\\d+\\]";
Comments