I want to remove xxxx-xxxx in string.
String data = "help text 2015-2016 dummy string";
Need output: help text dummy string
String data = "abcd 2057-3827 any string";
Need output: abcd any string
I want to remove xxxx-xxxx in string.
String data = "help text 2015-2016 dummy string";
Need output: help text dummy string
String data = "abcd 2057-3827 any string";
Need output: abcd any string
The following code should work:
String regexp = "[^\\s]{4}-[^\\s]{4}\\s";
String str = "help text 2015-2016 dummy string";
System.out.println(str.replaceFirst(regexp, ""));
If xxxx-xxxx
is always a number, then you can use:
String r = "[0-9]{4}-[0-9]{4}\\s";