Thread View: cn.bbs.comp.lang.java
1 messages
1 total messages
Started by cffile
Mon, 06 Apr 2009 05:39
java������ʽ
Author: cffile
Date: Mon, 06 Apr 2009 05:39
Date: Mon, 06 Apr 2009 05:39
30 lines
1817 bytes
1817 bytes
jdk1.4�м�����java.util.regex���ṩ��������ʽ��֧�֡�
����Java.lang.String���е�replaceAll��split����Ҳ�ǵ��õ�
������ʽ��ʵ�ֵġ�
��������ʽ���ַ�IJ�����Ҫ�������ַ�ƥ�䣬ָ���ַ�
�滻��ָ���ַ���Һ��ַ�ָ
example:
public static void main(String[] args) {
String regexp = "<\\s*([^>]*)\\s*>";
String source="<a href >td< table >";
Pattern pattern = Pattern.compile(regexp);
Matcher matcher = pattern.matcher(source);
StringBuffer sbr = new StringBuffer();
while (matcher.find()) {
System.out.println(matcher.group());
System.out.println(matcher.group(1));
}
}
output:
<a href >
a href
< table >
table
--
[m[1;33m�� ��Դ:�������ʵBBS bbs.tju.edu.cn��[FROM: 202.113.13.188][m
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads