Results 1 to 4 of 4
Thread: regrex
- 02-08-2012, 12:01 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 1
- Rep Power
- 0
regrex
I'm trying to use regrex to separate int values from a string. Here is what I have.
Scanner input = new Scanner(System.in);
String date = input.next();
Pattern p = Pattern.compile("-?\\d+");
Matcher ma = p.matcher(date);
ma.find();
while (ma.find())
{
System.out.println(ma.group());
}
It works ok...
I want to take the digits from a date format 02/03/04 or 3/5/2008
My output is
03
04
and
5
2008
Could someone tell me why the first set is being skipped?
Thanks!
- 02-08-2012, 01:10 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: regrex
Notice you are calling ma.find() twice before you ever call System.out.println();Java Code:ma.find(); while (ma.find()) { System.out.println(ma.group()); }
- 02-08-2012, 07:12 AM #3
Re: regrex
And the term is regex or RegEx or Regular Expressions. Not regrex.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks