By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

regex Pattern

P: n/a
I've got a 4 line message that looks like this:

Encountered "<EOF>" at line 1, column 7.
Was expecting one of:
"=" ...
"]]" ...

and want to get the line and column numbers
from it. This is what I am doing:

Pattern pattern =
Pattern.compile("at line (\\d+), column (\\d+)");
Matcher matcher = pattern.matcher(message);

if (matcher.matches())
{
System.out.println("match");
this.line = Integer.parseInt(matcher.group(1));
this.column = Integer.parseInt(matcher.group(2));
}
else
{
System.out.println("no match");
}

and I cannot get it to match. What is wrong?
Dean Hoover

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Dean,

You need to call the "find()" method of Matcher which looks for the
next subsequence that matches the pattern. The "matches()" method
tries to match the ENTIRE input string to the pattern, which in this
case would fail.

Steve

"Dean A. Hoover" <dh*******@yahoo.com> wrote in message news:<sa*******************@twister.nyroc.rr.com>. ..
I've got a 4 line message that looks like this:

Encountered "<EOF>" at line 1, column 7.
Was expecting one of:
"=" ...
"]]" ...

and want to get the line and column numbers
from it. This is what I am doing:

Pattern pattern =
Pattern.compile("at line (\\d+), column (\\d+)");
Matcher matcher = pattern.matcher(message);

if (matcher.matches())
{
System.out.println("match");
this.line = Integer.parseInt(matcher.group(1));
this.column = Integer.parseInt(matcher.group(2));
}
else
{
System.out.println("no match");
}

and I cannot get it to match. What is wrong?
Dean Hoover

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.