Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

Regular Expression problem

Thread view: 
dhinakar_ve@yahoo.com - 10 Aug 2007 02:26 GMT
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
Arne Vajhøj - 10 Aug 2007 03:03 GMT
> I am trying to parse the string algoParameters to get the strings
> between the delimiter | using java.util.regex.Pattern class. But I am
[quoted text clipped - 30 lines]
> 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
Roedy Green - 10 Aug 2007 03:14 GMT
> What is the
>metacharacter to represent any ascii character other than whitespaces.

see http://mindprod.com/jgloss/regex.html
\S \S+
related (\p{Alpha}+)
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

dhinakar_ve@yahoo.com - 10 Aug 2007 03:57 GMT
On Aug 9, 10:14 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> > What is the
> >metacharacter to represent any ascii character other than whitespaces.
[quoted text clipped - 5 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

\S+ matches the whole line. I get the original string as the match.
Michael Jung - 10 Aug 2007 07:39 GMT
> On Aug 9, 10:14 pm, Roedy Green <see_webs...@mindprod.com.invalid>
> wrote:
[quoted text clipped - 8 lines]
> > The Java Glossaryhttp://mindprod.com
> \S+ matches the whole line. I get the original string as the match.

Split the beast on | first. Or do \d=[^|]+

Michael
dhina - 10 Aug 2007 12:25 GMT
> dhinakar...@yahoo.com writes:
> > On Aug 9, 10:14 pm, Roedy Green <see_webs...@mindprod.com.invalid>
[quoted text clipped - 13 lines]
>
> Michael

\d=[^|]+  works.
Thanks for the help.
Dhina


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.