Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Java in General and the fly likes question about regexp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "question about regexp" Watch "question about regexp" New topic

question about regexp

Johan Ee

Joined: May 24, 2008
Posts: 4
Hi guys!

So, i have this regexp:
Pattern p = Pattern.compile("^([A-Z]{2})_([A-Z]{1,2})([0-9]{2})-([0-9]{3,5}).(\\w+)");
Matcher matcher = p.matcher(aString);

So, if I get a match... How can I "collect" each one of these (from aString):
[A-Z]{2}) , ([A-Z]{1,2}), ([0-9]{2}), ([0-9]{3,5}), (\\w+)")
and put them in a variable??

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41640
Don't know, but when I have that sort of problem, my first port of call will be the Java Tutorials.
I agree. Here's the link:
subject: question about regexp