
本文共 4009 字,大约阅读时间需要 13 分钟。
������������������Regular Expression���������regex������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
1. ������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������
"abcd"
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
2. ������������������
���������������������������������[]
���������������������������������������������������&
���|
������������������������������������������������
���������������������
[abc]
���������a���b���c������������������������[a-z]
���������������������a���z������������[^a-z]
���������������a���z������������������������������������������������������
���������������������
[a-z&^c]
���������a���c������������������������������[a-zA-Z0-9@!#]
������������������������������������������@���!���#������������������
3. ������������������
������������������������������������������������������������������������������������������������������������
- ���������������
.
������������������������������/
���������������������������������[0-9]
���w
���������������������������������[a-zA-Z0-9]
���s
������������������������������������������������������������������������������d
���������������������������w
���������������������������s
���������������������������
4. ������������������
���������������������������������������������������������������������������������������������
- ������������������������
*
���������������������������������������������������?
���������������������������������������+
���������������������������������������������������{n}
���������������n������{n,}
���������n���������������{n,m}
���������n������m������������
���������
a*
������������������������a���(agc)?
���������agc
���������������������������/d{3}b
������������d������������������������������������������������
5. ���������������������
������()
���������������������������������������������������������������������������
- ���������������������������������
- ���������������������������������������������
- ������������
|
������������������������
���������
(one|two)?
���������������one
���two
���������������(www|baidu).com
������������www
���baidu
������������������
6. ���������������������
^
���&
���������������������������������������������������
^
������������������������������������&
������������������������������������^
���&
������������������������������������������������������������������
���������������
\
���������������������������������������������������������������������������������- ������������������������������������������������Java���������������������
7. ������������������������������������������
1. Java������������
String������������
matches()
������������������������������������������������������������split()
������������������������������������������������replaceAll()
���������������������������replaceFirst()
���������������������������������
Pattern������Matcher������
- ������
Pattern.compile
������������������ Matcher.find()
������������������������������������������������Matcher.lookingAt()
������������������������������������������������
- ������
���������������
Pattern pattern = Pattern.compile("\\d{3}");Matcher matcher = pattern.matcher("abc123dgh");System.out.println(matcher.matches()); // falseSystem.out.println(matcher.find()); // trueSystem.out.println(matcher.lookingAt()); // false
2. ���������������������
No other languages are covered in this document.发表评论
最新留言
关于作者
