Java Regex/Pattern Matching

Associate
Joined
30 Dec 2008
Posts
422
Location
York
Right,

I'm tearing my hair out with this and I'm not happy. Someone from OcUK please help me!

I need to get characters in from the command line, of the form:

(NUMBER *comma* NUMBER *comma* ... ... )

When the user types this in, I need to take all of the numbers and add them to an integer array. I've used pattern matching before, but only on Strings. Is this doable? I can't seem to get it working myself. Sorry, using Java as the language.

Thanks.
 
Non integers may crop up accidentally, but they should be caught elsewhere. This only needs to find positive integers from that form and whack them in an array.

Moogle, I tried something similar to that and it never matched anything, but I probably did it wrong.

Top dog's sounds promising, but I'm a bit confused as to what it'll actually return.
 
Well, I previously tried just \\d+ and it never matched anything. There's clearly a problem elsewhere in my code, I think I might go for a shower and then try again.

Thanks for the suggestions.
 
Sorry for leaving last night, I went to bed instead.

This morning I decided to delete and start the method again. Low and behold, \\d+decides to work fine. No idea why it didn't before, don't much care either :p

Thanks for all the help guys. Much better mood today.
 
I actually never considered it, mainly because I believed it was old hat now. I remember using it a few years ago at college, but reading then that it wasn't the best way of doing things. Maybe I'm wrong?

Edit - The Java site says it's not recommended for use any more. I guess it would have been easier to do it that way, but hey ho.
 
Last edited:
Back
Top Bottom