Regular Expression problem

D

dhinakar_ve

I am trying to parse the string algoParameters to get the strings
between the delimiter | using java.util.regex.Pattern class. But I am
not able to get the characters after the letter "-". What is the
metacharacter to represent any ascii character other than whitespaces.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String algoParameters = "57=PSHORT|5062=20050110-15:01:00|
5063=20050110-16:01:00|";

Pattern algoPattern = Pattern.compile("\\d+=[\\w]+
[|]?");
Matcher m = algoPattern.matcher(algoParameters);
while (m.find())
{
String matchedText = m.group();
int matchedFrom = m.start();
int matchedTo = m.end();
System.out.println("matched [" + matchedText +
"] " + "from " + matchedFrom + " to " + matchedTo + ".");

System.out.println(algoParameters.substring(matchedFrom, matchedTo));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
But I get the following output:
matched [57=PSHORT|] from 0 to 10.
57=PSHORT|
matched [5062=20050110] from 10 to 23.
5062=20050110
matched [5063=20050110] from 33 to 46.
5063=20050110

I am expecting
57=PSHORT
5062=20050110-15:01:00
5063=20050110-16:01:00
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

I am trying to parse the string algoParameters to get the strings
between the delimiter | using java.util.regex.Pattern class. But I am
not able to get the characters after the letter "-". What is the
metacharacter to represent any ascii character other than whitespaces.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String algoParameters = "57=PSHORT|5062=20050110-15:01:00|
5063=20050110-16:01:00|";

Pattern algoPattern = Pattern.compile("\\d+=[\\w]+
[|]?");
Matcher m = algoPattern.matcher(algoParameters);
while (m.find())
{
String matchedText = m.group();
int matchedFrom = m.start();
int matchedTo = m.end();
System.out.println("matched [" + matchedText +
"] " + "from " + matchedFrom + " to " + matchedTo + ".");

System.out.println(algoParameters.substring(matchedFrom, matchedTo));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
But I get the following output:
matched [57=PSHORT|] from 0 to 10.
57=PSHORT|
matched [5062=20050110] from 10 to 23.
5062=20050110
matched [5063=20050110] from 33 to 46.
5063=20050110

I am expecting
57=PSHORT
5062=20050110-15:01:00
5063=20050110-16:01:00

You could explicit allow minus and colon as characters.

Non whitespace is \S, but that would match | as well.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top