Html的正则表达式

来源:互联网 发布:阿里云网站免费模板 编辑:程序博客网 时间:2024/04/30 15:27

这个是我们经常需要用到的.所以做了一个:

 /*

 * Main.java
 *
 * Created on 2006127, 上午10:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
 
package regex;
 
/**
 *
 * @author longronglin
 */
import java.util.regex.*;
 
public class Main
{
   
    /** Creates a new instance of Main */
    public Main()
    {
    }
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        String htmlStr = "<table><br>this is a test</br></table>";
        String patternString = "(<+[a-z//s]+>)|(</+[a-z//s]+>)";
        Pattern pattern = Pattern.compile (patternString);
        Matcher matcher = pattern.matcher(htmlStr);
       
        while(matcher.find ())
        {
            int start = matcher.start();
            int end = matcher.end();
            String mache = htmlStr.substring(start,end);
            System.out.println (start);
            System.out.println (end);
            System.out.println (mache);
        }
        System.out.print ("success");
    }
   
}
 
结果:
init:
deps-jar:
Compiling 1 source file to D:/fenci/regEx/build/classes
compile:
run:
0
7
<table>
7
11
<br>
25
30
</br>
30
38
</table>
success
生成成功(总时间:1 秒)

 

原创粉丝点击