473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

regex Pattern

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
1 1989
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
1
by: Craig Kenisston | last post by:
Hi, I need to write a function that should behave like the SQL's "like" operator on a list of words. I was wondering if I can use Regex directly to do this job. But I've been reading about...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
9
by: Whitless | last post by:
Okay I am ready to pull what little hair I have left out. I pass the function below my String to search, my find string (a regular expression) and my replace string (another regular expression)....
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
4
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
8
by: tomb | last post by:
I have found much documentation on specific patterns, but I can't find anything explaining how to reject strings that match both groups. My string could contain specific letters or numbers. If...
8
by: sherifffruitfly | last post by:
Hi, I've been searching as best I can for this - coming up with little. I have a file that is full of lines fitting this pattern: (?<year>\d{4}),(?<amount>\d{6,7}) I'm likely to get a...
1
by: Prabhu Gurumurthy | last post by:
Hello all - I have a file which has IP address and subnet number and I use regex to extract the IP separately from subnet. pattern used for IP: \d{1,3}(\.\d{1,3}){3} pattern used for...
0
by: vmysore | last post by:
I am trying to get all the columns selected within a SQL query (including the sub selects). When the code hits matcher.find(). i get the following exception: Exception in thread "main"...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.