LINEMAN78
27 Mar 2009, 4:40 PM
I know this is probably a stupid question, but I cannot find a solution anywhere. Is there a way to perform regex on a string and have access to the groups? I really don't want to have to make a server call in order to parse the string. I am simply trying to parse a phone number into the 3 distinct sections. Below is how I would implement it it I were to do it in Java:
Pattern phonePattern = Pattern.compile("^((\\((\\d{3})\\)(\\d{3})-(\\d{4}))|((\\d{3})-(\\d{3})-(\\d{4})))$");
String voiceNum = (String)phoneNumberItem.getValue();
String[] voiceNumSplit = new String[3];
Matcher voiceMatcher = phonePattern.matcher(voiceNum);
for (int i = 0; i < voiceMatcher.groupCount(); i++)
Window.alert("Group "+i+": "+voiceMatcher.group(i));
Pattern phonePattern = Pattern.compile("^((\\((\\d{3})\\)(\\d{3})-(\\d{4}))|((\\d{3})-(\\d{3})-(\\d{4})))$");
String voiceNum = (String)phoneNumberItem.getValue();
String[] voiceNumSplit = new String[3];
Matcher voiceMatcher = phonePattern.matcher(voiceNum);
for (int i = 0; i < voiceMatcher.groupCount(); i++)
Window.alert("Group "+i+": "+voiceMatcher.group(i));