regex - Java split method -
i trying split inputted number such (123) 456-7890.
string [] split = s.split(delimiters);
i have been searching web ways of delimiting area code inside set of parentheses haven't found works case. not know if array messing printing either. array not required did not know else since required use split method.
import java.util.regex.matcher; import java.util.regex.pattern; public class helloworld{ public static void main(string[] args){ string phonenumber = "(123)-456-7890"; string pattern = "\\((\\d+)\\)-(\\d+)-(\\d+)"; pattern p = pattern.compile(pattern); matcher m = p.matcher(phonenumber); if (m.find()) system.out.println(m.group(1) + " " + m.group(2) + " " + m.group(3)); } }
you can try here.
Comments
Post a Comment