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 / July 2006

Tip: Looking for answers? Try searching our database.

java regex

Thread view: 
D i s h a n - 19 Jul 2006 08:30 GMT
Hi,

I want to find out the pattern as follows

text = "XYZ 34 N TO 763427894"

XYZ and 'N TO' are fixed. only numbers can change. please help me to
find regex for this text.

Thanks in advance
DF
TechBookReport - 19 Jul 2006 10:33 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> Thanks in advance
> DF

What have you tried so far?

Signature

TechBookReport Java - http://www.techbookreport.com/JavaIndex.html

Oliver Wong - 19 Jul 2006 15:44 GMT
> Hi,
>
[quoted text clipped - 4 lines]
> XYZ and 'N TO' are fixed. only numbers can change. please help me to
> find regex for this text.

   If you're unable to come up with the regexes, why don't you fall back to
a simpler solution? For example, scanning the string until you find a digit?

   - Oliver
Frank Langelage - 19 Jul 2006 21:18 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> Thanks in advance
> DF

Did not try it but "^XYZ \\d+ N TO \\d+$" is near to the final answer.
IchBin - 19 Jul 2006 21:21 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> Thanks in advance
> DF

There are a lot of ways you could do this.

    String text = "XYZ 34 N TO 763427894";
    //
    // split on  whitespace character "\\s" or [ \t\n\x0B\f\r]
    String values[] = text.split("\\s");
    //
    // or what ever numeric type you want
    int number1 = Integer.parseInt(values[1]);
    int number2 = Integer.parseInt(values[4]);

Or you could check for non-digit
     //
     // split on A non-digit: "\\D" or [^0-9]
     String values[] = text.split("[^0-9]");

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA              http://weconsultants.phpnet.us
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)


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



©2008 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.