Click here to watch in Youtube :
https://www.youtube.com/watch?v=DwLcMtL03pU&index=48&list=UUhwKlOVR041tngjerWxVccw
RegexDemo.java
Output
https://www.youtube.com/watch?v=DwLcMtL03pU&index=48&list=UUhwKlOVR041tngjerWxVccw
RegexDemo.java
/**
* Write a regular expression which matches any phone number
*/
public class RegexDemo
{
public static void main(String[] args)
{
String regex = "\\d\\d\\d([-]){1}\\d\\d\\d([-]){1}\\d\\d\\d\\d";
String phoneNum1 = "123-332-9999";
System.out.println(phoneNum1.matches(regex));// true
String phoneNum2 = "1233329999";
System.out.println(phoneNum2.matches(regex));// false
}
}
* Write a regular expression which matches any phone number
*/
public class RegexDemo
{
public static void main(String[] args)
{
String regex = "\\d\\d\\d([-]){1}\\d\\d\\d([-]){1}\\d\\d\\d\\d";
String phoneNum1 = "123-332-9999";
System.out.println(phoneNum1.matches(regex));// true
String phoneNum2 = "1233329999";
System.out.println(phoneNum2.matches(regex));// false
}
}
Output
true
false
false
https://sites.google.com/site/ramj2eev1/home/javabasics/RegexDemo_phone_number.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/RegexDemo_phone_number
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/ef02c9011c18b0aa670526ba89cc11f493b9b854/BasicJava/RegexDemo_phone_number/?at=master
See also:
No comments:
Post a Comment