Results 1 to 1 of 1
Thread: Using regex
- 03-28-2010, 11:07 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 31
- Rep Power
- 0
Using regex
I have a program in which i'm creating TelephoneNumber objects which have ints areaCode exchangeCode and number. I'm using a regex to make sure that the input is an actual phone number. I want to know if there is a way to use a back reference to assign the first three numbers to areaCode, the second 3 to exchange code and the last 4 to number. My code is below
Back reference 1 needs to equal to areaCode, 2 equal to exchangeCode and 3 to number but I don't know how to do this.Java Code:private static int areaCode, exchangeCode, number; public TelephoneNumber(String phoneNumber){ Pattern pattern = Pattern.compile("(\\d{3})-(\\d{3})-(\\d{4})"); Matcher matcher = pattern.matcher(phoneNumber); if(matcher.matches()) System.out.println("valid phone number"); else System.out.println("invalid phone number"); }
Similar Threads
-
regex question
By mac in forum New To JavaReplies: 6Last Post: 03-17-2010, 05:57 AM -
Interpretation of regex?
By Ms.Ranjan in forum New To JavaReplies: 2Last Post: 04-23-2009, 06:37 PM -
Multiline Regex
By zriggle in forum New To JavaReplies: 1Last Post: 02-26-2009, 04:49 AM -
Some help with regex and loop
By moaxjlou in forum New To JavaReplies: 21Last Post: 11-02-2008, 10:24 PM -
[SOLVED] More RegEx help
By JT4NK3D in forum New To JavaReplies: 2Last Post: 05-23-2008, 04:07 AM


LinkBack URL
About LinkBacks

Bookmarks