This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular expression" Watch "Regular expression" New topic
Author

Regular expression

Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
If I have a String like below:

me@my.com|ClientId=12345|GUID=klsLDFjlSf09SDf9|KeygenLoc=APPLIANCE|

How can I parse out the Client ID (i.e. the "12345" on its own) value via a regular expression?

Many thanks!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38033
    
  22
Do you need a regex?
Try myString.substring(myString.indexOf("ClientID=") + "ClientID=".length(), myString.indexOf("|GUID"));

Try getting the () paired off correctly!
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
Yip, needs to be a regex!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18538
    
  40

Originally posted by Kev D'Arcy:
Yip, needs to be a regex!


What have you tried so far? It is pretty straightforward -- can be done with a single method call.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
Don't get me started about those stupid light bulbs.
 
subject: Regular expression
 
Similar Threads
How can I add error handling facilities to this code?
Validating The Date String
Regular Expression requred to get Java class names from text file
Questions of Javascript Regular Expression
regular expression which doesnt alllow *