0

Suppose I have a string "July is busy". And I need the string without "July". How can I do it with using regex ?

Thanks.

2
  • 2
    Why "July"? First word? Word with capital letters? You have July elsewhere? Before "is"? Who knows. Commented Dec 14, 2010 at 18:20
  • 1
    String strWithoutJuly = " is busy"; Commented Dec 14, 2010 at 18:56

2 Answers 2

2

So you want to remove the first word from a string?

Try

String resultString = subjectString.replaceAll("^\\s*\\w+\\s*", "");
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for reply. But my problem is that my employer does not want any string function.
Wow, your "employer" sounds a lot more like an "instructor"
I dont know what will my employer say. But I think this is the best solution. Thanks.
1

You can do something like this:

import java.util.regex.*;
Matcher m = Pattern.compile("^July(.*)\$").matcher("July is busy");

// if you had a match, the extra would be here:
if (m.matches()) {

    // match count:
    m.groupCount();

    // ' is busy'
    String rightOfJuly = m.group(1);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.