(String[] args)
| 10 | */ |
| 11 | public class RegexDemo { |
| 12 | public static void main(String[] args) { |
| 13 | // ģʽ�����ƥ��������Ļ���ʹ�� |
| 14 | // // �ѹ���ת��Ϊģʽ���� |
| 15 | // Pattern p = Pattern.compile("a*b"); |
| 16 | // // ͨ��ģʽ����õ�ƥ�������� |
| 17 | // Matcher m = p.matcher("aaaaab"); |
| 18 | // // ͨ��ƥ����������ù��� |
| 19 | // boolean b = m.matches(); |
| 20 | // System.out.println(b); |
| 21 | |
| 22 | // ��Ϊ�ж���˵ |
| 23 | // String s = "aaaaab"; |
| 24 | // String regex = "a*b"; |
| 25 | // boolean flag = s.matches(regex); |
| 26 | // System.out.println(flag); |
| 27 | |
| 28 | // ����ȡ���� |
| 29 | // ��ȡ�������ַ���ɵĵ��� |
| 30 | String s = "da jia hao,wo men dou hen ai java."; |
| 31 | // ������� |
| 32 | String regex = "\\b[a-z]{3}\\b"; |
| 33 | |
| 34 | Pattern p = Pattern.compile(regex); |
| 35 | Matcher m = p.matcher(s); |
| 36 | |
| 37 | // public boolean find():���Ƿ���ƥ��� |
| 38 | // boolean b = m.find(); |
| 39 | // System.out.println(b); |
| 40 | // ���ǵ��ó��� |
| 41 | // public String group() |
| 42 | // String ss = m.group(); |
| 43 | // System.out.println(ss); |
| 44 | |
| 45 | // b = m.find(); |
| 46 | // System.out.println(b); |
| 47 | // // ���ǵ��ó��� |
| 48 | // // public String group() |
| 49 | // ss = m.group(); |
| 50 | // System.out.println(ss); |
| 51 | |
| 52 | while (m.find()) { |
| 53 | System.out.println(m.group()); |
| 54 | } |
| 55 | } |
| 56 | } |
nothing calls this directly
no outgoing calls
no test coverage detected