color group package .cn log ext [] ron
- package com.wujianbo.five;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Demo01 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String phone = "13541433525";
- String phoneEx = "^1[387]\\d{9}";
- Pattern pattern = Pattern.compile(phoneEx); //编译正则表达式
- Matcher matcherphone = pattern.matcher(phone);
- System.out.println(matcherphone.matches());
- }
- }
- package com.wujianbo.five;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Demo01 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //String phone= "13541433525";
- //String phoneEx= "^1[387]\\d{9}";
- //Pattern pattern= Pattern.compile(phoneEx);//编译正则表达式
- //Matcher matcherphone= pattern.matcher(phone);
- //System.out.println(matcherphone.matches());
- String telephone= "0512-85121234";
- String telephoneEx= "^0\\d{2,3}-[856]\\d{6,7}";
- System.out.println(Pattern.compile(telephoneEx).matcher(telephone).matches());
- }
- }
- package com.wujianbo.five;
- import java.util.regex.Pattern;
- public class Demo03 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //String email= "[email protected]";
- String email = "[email protected]";
- //String emailEx= "[a-zA-Z0-9{1,}@((a-zA-Z0-9-*){1,}\\.){1,3}[a-zA-Z\\-]{1,}";
- String emailEx = "[a-zA-Z0-9]{1,}@[a-zA-Z0-9]{1,}.[a-zA-Z0-9]{1,}.[a-zA-Z0-9]{1,}$";
- System.out.println(Pattern.compile(emailEx).matcher(email).matches());
- }
- }
- package com.wujianbo.five;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Demo02 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String source = "<input name=‘verify‘ value=‘3334dfafaddfa‘ type=‘hidden‘/>";
- String regEx = "(value=‘)(.+)(‘ type)";
- String tmp = "";
- Pattern p = Pattern.compile(regEx);
- Matcher m = p.matcher(source);
- //System.out.println(m.find());
- if (m.find()) {
- tmp = m.group(2);
- System.out.println(tmp);
- }
- }
- }
package com.wujianbo.five;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Demo02 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String source= "<input name=‘verify‘ value=‘3334dfafaddfa‘ type=‘hidden‘/>";
String regEx= "(value=‘)(.+)(‘ type)";
String tmp= "";
Pattern p= Pattern.compile(regEx);
Matcher m= p.matcher(source);
//System.out.println(m.find());
if(m.find()) {
tmp= m.group(2);
System.out.println(tmp);
}
}
}
【自动化__持续集成】___java___正则表达式
来源: http://www.bubuko.com/infodetail-2296944.html