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

首頁 > 學院 > 開發設計 > 正文

apache的Jakarta-ORO庫 的正則表達式的使用

2019-11-18 13:07:10
字體:
來源:轉載
供稿:網友

  apache的Jakarta-ORO庫 的正則表達式的使用
  ---附件是代碼和相關文件
  package regulareXPRessiontest.Jakarta_ORO;
  
  /**
  * <p>Title: </p>
  * <p>Description: </p>
  * <p>Copyright: Copyright (c) 2003</p>
  * <p>Company: </p>
  * @author wdz : wdz123@hotmail.com
  * @version 1.0
  */
  
  import org.apache.oro.io.*;
  import org.apache.oro.text.regex.*;
  
  public class Jakarta_OROTest1 {
  public Jakarta_OROTest1() {
  System.out.println("aaa121-0hhksjds找出第一個數字串");
  containMatch("aaa121-0hhksjds", "http://d+");
  
  System.out.println("從 3$xaaa121-0hhksjds 找出第一個[a-z]{4}[0-9]{3}");
  containMatch("3$xaaa121-0hhksjds", "[a-z]{4}[0-9]{3}");
  
  System.out.println("從 Catlog catherone cat cat1 catlog catherone 找出第一個cat[a-z]*//s+");
  preMatch("Catlog catherone cat cat1 catlog catherone", "cat[a-z]*//s+");
  
  ////找出第一個t*n
  System.out.println("ten tig找出第一個t*n");
  containMatch("ten tig", "[a-z]{1}.[a-z]{1}");
  
  System.out.println("獲得年月日");
  getDateString();
  
  // 找出所有 car*的單詞,單詞分割符號是空格符號或者逗號
  System.out.println("找出所有 car*的單詞,單詞分割符號是空格符號或者逗號");
  cycleMatch("Catlog catherone cat cat1 catlog catlog2 catherone", "((cat//w*))//s+",0);
  
  //找出所有的 擴號內的內容
  //使用 (( 和))配對使用可以進行分組,
  System.out.println("找出所有的 擴號內的內容");
  cycleMatch("Cuid=100(guest) gid=100(others) groups=10(users),11(floppy)", "[(]{1}((//w*))[)]{1}",1);
  
  //找出所有的日期字符串得月份
  //使用 (( 和))配對使用可以進行分組,
  System.out.println("找出所有的日期字符串的月份");
  cycleMatch("July 11, 2003 bbb 423434dfg*fg October 22, 2004", "(([a-z]{1,10}))//s[0-9]{1,2},[//s]?[0-9]{4}",1);
  
  
  //找出所有的 t*n
  System.out.println("找出所有的 [aeion]{1,2}n");
  cycleMatch("tan ten tin tonn toon","t[aeion]{1,2}n",0);
  
  //找出所有的 t*n
  // .用于站位,想當于文件查找得?符號
  System.out.println("找出所有的 t*n");
  cycleMatch("tan ten tin,tonn toon","((t.n))[//s,]?",1);
  
  //123-12-1234和123121234形式的社會安全號碼
  System.out.println("123-12-1234和123121234形式的社會安全號碼");
  cycleMatch("t199-12-1234n toon 122-80-7875 434338899","http://d{3}//-?//d{2}//-?//d{4}",0);
  //電話號碼
  System.out.println("電話號碼");
  cycleMatch("t023-67890221n toon023-88890221 4312906677","http://d{3}//-?//d{8}",0);
  
  //ip列表
  System.out.prin猀??獡????у耈ф?慰檔????擴牥慮整?傳??????????????????????????????????????????佄???偁??????????????侰?????????偁????????????楈敢湲瑡???????????????????佄??????????????????楈敢湲瑡?????????????????俄????擴牥慮整?????????????????????佄?溜????????????????楈敢湲瑡??????????????????????楈敢湲瑡??????????????????????????????????????????????????????????????????擴牥慮整?????????????楈敢湲瑡???????????????????????????????????????????????????????癡湩??????????????擴牥慮整????????楈敢湲瑡???????????????????擴牥慮整????????????????????????????????????????????擴牥慮整??????????????????????????????????????????????????????????溜??????????????楈敢湲瑡??????????????????擴牥慮整?????????六???????????????楈敢湲瑡???????????????????????????????????????????擴牥慮整???????????????????????????????????????????????????????????????擴牥慮整??????瑨灴?栯擴牥慮整昮湡慫?潣???????擴牥慮整???????????a??? tln("ip list --192.168.200.10,192.168.201.11獲得ip列表");
  cycleMatch("ip list --192.168.200.10,192.168.211.51","http://d{1,3}//.//d{1,3}//.//d{1,3}//.//d{1,3}",0);
  
  }
  
  /***
  *
  * 獲得年月日,
  * 例如 :June 26, 1951
  * */
  private void getDateString() {
  System.out.println("獲得年月日 ,從dsds June 26, 1951 ksdjks 找出第一個日期");
  containMatch(" dsds June 26, 1951 ksdjks ",
  "[a-z]+//s[0-9]{1,2},//s[0-9]{4}");
  System.out.println("獲得年月日 ,從June 16, 1959 asdsds June 11, 1911 ksdjks 找出第一個日期");
  containMatch("June 16, 1959 asdsds June 11, 1911 ksdjks ",
  "[//s]?[a-z]+//s[0-9]{1,2},//s[0-9]{4}");
  }
  
  /***
  * 前綴方式的匹配
  * @param inputValue 被匹配查找得對想
  * @param reg 匹配規則
  * **/
  private void preMatch(String inputValue, String reg) {
  PatternCompiler compiler = new Perl5Compiler();
  PatternMatcher matcher = null;
  Pattern pattern = null;
  String input = inputValue;
  String regexp = reg;
  try {
  pattern = compiler.compile(regexp, Perl5Compiler.CASE_INSENSITIVE_MASK);
  matcher = new Perl5Matcher();
  if (matcher.matchesPrefix(input, pattern)) {
  MatchResult result = matcher.getMatch();
  System.out.println("result =" + result.group(0));
  //System.out.println("result ="+result.group(1));
  }
  }
  catch (MalformedPatternException e) {
  System.err.println("preMatch--Bad pattern.");
  System.err.println(e.getMessage());
  System.exit(1);
  }
  }
  
  /***
  * 包含方式的匹配
  * @param inputValue 被匹配查找得對想
  * @param reg 匹配規則
  * **/
  private void containMatch(String inputValue, String reg) {
  // System.out.println("containMatch----");
  PatternCompiler compiler = new Perl5Compiler();
  PatternMatcher matcher = null;
  Pattern pattern = null;
  String input = inputValue;
  String regexp = reg;
  try {
  pattern = compiler.compile(regexp, Perl5Compiler.CASE_INSENSITIVE_MASK);
  matcher = new Perl5Matcher();
  if (matcher.contains(input, pattern)) {
  MatchResult result = matcher.getMatch();
  System.out.println("result =" + result.group(0));
  // System.out.println("result ="+result.group(1));
  }
  }
  catch (MalformedPatternException e) {
  System.err.println("containMatch ---Bad pattern.");猀??獡????
  System.err.println(e.getMessage());
  System.exit(1);
  }
  }
  /***
  * 循環方式的匹配
  * 使用 (( 和))配對使用可以進行分組
  * @param inputValue 被匹配查找得對想
  * @param reg 匹配規則
  * **/
  private void cycleMatch(String inputValue, String reg,final int groupid){
  org.apache.oro.text.regex.PatternCompiler compile = new Perl5Compiler();
  try {
  Pattern p = compile.compile(reg,Perl5Compiler.CASE_INSENSITIVE_MASK);
  PatternMatcherInput input = new PatternMatcherInput(inputValue);
  org.apache.oro.text.regex.Perl5Matcher pm = new Perl5Matcher();
  MatchResult result =null;
  int i=0;
  while(pm.contains(input,p)){
  result = pm.getMatch();
  System.out.println("result =" + result.group(groupid));
  input.setBeginOffset(result.length());
  i++;
  }
  System.out.println("總共匹配"+i+"次");
  }
  catch (Exception ex) {
  System.err.println("循環方式的匹配發生錯誤"+ex.getMessage());
  }
  }
  
  public static void main(String[] args) {
  Jakarta_OROTest1 jakarta_OROTest11 = new Jakarta_OROTest1();
  }
  
  }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 溧水县| 隆德县| 抚顺县| 德庆县| 天气| 成都市| 方山县| 汪清县| 潮安县| 南丰县| 乌兰县| 永靖县| 横峰县| 增城市| 讷河市| 乌审旗| 仲巴县| 南雄市| 封开县| 高尔夫| 谢通门县| 乃东县| 肥乡县| 当涂县| 黎川县| 喀喇沁旗| 灌云县| 汉中市| 云南省| 沁源县| 湖北省| 靖西县| 台州市| 紫阳县| 星子县| 天长市| 淳安县| 永康市| 衢州市| 九寨沟县| 永年县|