-2

I want to remove xxxx-xxxx in string.

  1. String data = "help text 2015-2016 dummy string";

    Need output: help text dummy string

  2. String data = "abcd 2057-3827 any string";

Need output: abcd any string

1
  • 3
    Pure code-writing requests are off-topic on Stack Overflow -- we expect questions here to relate to specific programming problems -- but we will happily help you write it yourself! Tell us what you've tried, and where you are stuck. This will also help us answer your question better. Commented Feb 1, 2016 at 4:35

1 Answer 1

1

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";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it's working fine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.