Java regex: Get the matched sequence?

If you only want to return part of the match, use capturing parentheses For example, to get only the year out of an MM/DD/YYYY date, the regex you want is d{2}/\d{2}/(\d{4}) I don't know the specifics of doing it in Java (you might need to escape some characters, for example), but just knowing that you should look for "capturing groups" should be of use.

If you only want to return part of the match, use capturing parentheses. For example, to get only the year out of an MM/DD/YYYY date, the regex you want is \d{2}/\d{2}/(\d{4}) I don't know the specifics of doing it in Java (you might need to escape some characters, for example), but just knowing that you should look for "capturing groups" should be of use.

What you can do is something similar to the following: Pattern p = Pattern. Compile("\\w"); // Replace "\\w" with your pattern String str = "Some String To Match"; Matcher m = p. Matcher(str); List matches = new ArrayList(); while(m.find()){ matches.

Add(m.group()); } After this, matches will contain every substring that matched the Pattern. In this case, it is just every letter, excluding spaces. If you want to turn a List into a String just use: String matchArr = matches.

ToArray(new Stringmatches.size()).

I can't figure out how to do this in Java. Match.group() returns the whole string. Is this impossible?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions