国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java正則表達式使用示例

2019-11-26 15:36:12
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

package com.hongyuan.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexTest {
 public static void main(String[] args) {
  String str="<html><head><title>regex test</title></head><body><p>this is a simle regex test</p></body></html>";

  //拆分字符串
  String[] splitStr=Pattern.compile("[</?|>]").split(str);
  for(int i=0;i<splitStr.length;i++){
   System.out.print(splitStr[i]+" ");
  }
  System.out.println();

  //判斷字符串是否與制定模式匹配
  boolean isMatching = Pattern.compile("^<(//w*)>.*<///1>$").matcher(str).matches();
  System.out.println(isMatching);

  //替換字符串
  String repStr=Pattern.compile("<(/?)p>").matcher(str).replaceAll("<$1h1>");
  System.out.println(repStr);

  //提取字符串
  Matcher m = Pattern.compile("<title>(.*)</title>").matcher(str);
  while(m.find()){
   System.out.println(m.group(1));
  }  
 }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鸡东县| 吴江市| 三台县| 庄河市| 永靖县| 简阳市| 思南县| 四平市| 阿坝| 汶川县| 都匀市| 昭通市| 田东县| 桃园县| 波密县| 隆化县| 西乡县| 射洪县| 荥阳市| 白银市| 汉沽区| 合江县| 嘉兴市| 香河县| 临颍县| 金阳县| 千阳县| 碌曲县| 江城| 阿巴嘎旗| 金沙县| 吉首市| 莱芜市| 云梦县| 习水县| 彭水| 太康县| 威海市| 定日县| 修文县| 雅江县|