🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #329

java������ʽ

#329
From: cffile
Date: Mon, 06 Apr 2009 05:39
30 lines
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           

--
�� ��Դ:�������ʵBBS bbs.tju.edu.cn��[FROM: 202.113.13.188]
Technical Details
Message-ID: <4fJEdb$AWM@bbs.tju.edu.cn>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.neu.edu.cn!news.byr.edu.cn!TJU

Show Full Headers
Complete Article Headers
X-Google-Thread: f6cb0,6ad58050a76d0d88,start
X-Google-Attributes: gidf6cb0,domainid0,public,usenet
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.neu.edu.cn!news.byr.edu.cn!TJU
From: cffile.bbs@bbs.tju.edu.cn.no.spam (cffile)
Newsgroups: cn.bbs.comp.lang.java
Subject: java������ʽ
Date: 06 Apr 2009 05:39:01 GMT
Organization: �����ʵBBSվ
Message-ID: <4fJEdb$AWM@bbs.tju.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: Java/M.1238996341.A
Lines: 29