Henry Wong wrote:The group() method returns the result from a match... but you didn't tell the regex to match anything. You need to actually perform a match (and succeed) before you can get the result from it.
Henry
Abdulmalik Malik wrote:
but this what happens in line 13, doesn't it?
Henry Wong wrote:
Abdulmalik Malik wrote:
but this what happens in line 13, doesn't it?
No. Line 13 just creates a Matcher instance, from the Pattern instance. This is *not* telling the regex engine to perform a match -- that is done with the matcher instance (using either the matches() or find() method).
Perhaps, the regex javadoc is a good place to start here.
Henry
Abdulmalik Malik wrote:
I agree with what you have said line 13, but what I know -and please correct me if I'm mistaken- that matcher.group(2) returns the matched String, so what's wrong with my code?
Abdulmalik Malik wrote:
Especially that I tried other methods than (group) like groupCount() and it did work!
Abdulmalik Malik wrote:Thanks again, and sorry for being a pain!
but I tried the following, and it worked as well:
Henry Wong wrote:
Abdulmalik Malik wrote:Thanks again, and sorry for being a pain!
but I tried the following, and it worked as well:
I don't know what else to tell you. It shouldn't work.
But I would like to see this (complete and compilable) working code. Can you post it?
Henry
Henry Wong wrote:You said that there was a call to group() that worked, where is that?
Henry
Abdulmalik Malik wrote:
You need to actually perform a match (and succeed) before you can get the result from it.
that is done with the matcher instance (using either the matches() or find() method).
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Prime wrote:
Abdulmalik Malik wrote:
And there is the line that makes it work - an actual search in the String for the regex. As Henry already saidYou need to actually perform a match (and succeed) before you can get the result from it.
that is done with the matcher instance (using either the matches() or find() method).
Consider Paul's rocket mass heater. |