package dk.day14;
public class Dk1Regex {
public static void main(String[] args) {
String regex = "[1-9][\\d] {4,14}";
System.out.println("12345".matches(regex));
}
public static boolean qq(String qq) {
boolean flag = true;
if (qq.length() > 5 && qq.length() < 15) {
if (!qq.startsWith("0")) {
char[] arr = qq.toCharArray();
for (int i = 0;i < arr.length;i++) {
char temp = arr[i];
if(!Character.isDigit(temp)) {
flag = false;
break;
}
}
}else {
flag = false;
}
}else {
flag = false;
}
return flag;
}
}
String regex = "[abcd]";
String regex = "[^abc]";
String regex = "[a-zA-Z]";
String regex = "[a-z[A-Z]]";
String regex = "[a-z&&[def]]";
String regex = "[a-z&&[^d-f]]";
String regex = ".";
String regex = "\\d";
String regex = "\\D";
String regex = "\\s";
String regex = "\\S";
String regex = "\\w";
String regex = "\\W";
String regex = "[abc]?"
String regex = "[abc]*"
String regex = "[abc]+"
String regex = "[abc]{n}"
String regex = "[abc]{n,m}"
package dk.day14;
import java.util.Arrays;
public class Dk2Regex {
public static void main(String[] args) {
String s = "91 27 46 38 50";
String[] arr = s.split(" ");
int[] iArr = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
iArr[i] = Integer.parseInt(arr[i]);
}
Arrays.sort(iArr);
System.out.println(arr2String(iArr));
}
public static String arr2String(int[] arry) {
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i = 0;i < arry.length;i++ )
{
if (i == arry.length - 1)
{
sb.append(arry[i]).append("]");
}else
sb.append(arry[i]).append(",");
}
return sb.toString();
}
}
String s = "itcast";
String regex = "[abc]";
String s1 = s.replaceAll(regex,"oo");
String regex = "(.)\\1(.)\\2";
System.out.println("高高兴兴".matches(regex));
String regex = "(..)\\1";
String regex = "(.)\\1{3}"
String regex = "(.)\\1+"
String s = "skdddfgggkj"
System.out.println(s.spilt(regex));
String s = "我。。。。。。要要要。。。。学。。编程";
String s2 = s.replaceAll("\\.+","");
String s3 = s2.replaceAll("(.)\\1+","$1");
String str = "我的电话是12345678901";
String regex = "1[34578]\\d{9}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
boolean b = m.find();
String s = m.group();
while(m.find)
System.out.println(m.group());