MCPcopy Create free account
hub / github.com/DuGuQiuBai/Java / main

Method main

day14/code/day14_Regex/src/cn/itcast_05/RegexDemo.java:12–55  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

10 */
11public 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected