Java中正規表示式

2021-08-30 07:42:20 字數 928 閱讀 3185

jakarta oro一套文字處理工具,能提供perl5.0相容的正規表示式,awk-like正規表示式, glob表示式。
還提供替換,分割,檔名過慮等功能
package com.yesky.apachelog.util.regex;

import org.apache.oro.text.regex.malformedpatternexception;

import org.apache.oro.text.regex.matchresult;

import org.apache.oro.text.regex.pattern;

import org.apache.oro.text.regex.patterncompiler;

import org.apache.oro.text.regex.patternmatcher;

import org.apache.oro.text.regex.perl5compiler;

import org.apache.oro.text.regex.perl5matcher;

/** * 解析字串: 返回符合記錄的一行記錄

* * @author 110

* */

public class apacheregexstring catch (malformedpatternexception e)

patternmatcher matcher = new perl5matcher();

if (matcher.contains(alinestring, pattern))

return null; }

public static void main(string args)

}

在這裡附上對應的jar包

Java中 正規表示式

字元類 abc a b 或 c abc 任何字元,除了abc a za z a 到 z 或 a 到 z 兩頭的字母包括在內 0 9 0到9 的字元都包括 預定義字元類 任何字元 d 數字 0 9 示例 判斷手機號的規則 string regex 1 3 9 d boolean flag phone....

Java中正規表示式的使用

正規表示式需要先建立乙個pattern,然後再用這個物件去match乙個字串,然後程式會把匹配的字串儲存在matcher物件,你可以通過find屈遍歷這個matcher,得到每乙個子串。以下是我寫的樣例程式 string content 1.gif fdjalkfd 2.gif fasdafsd p...

Java中正規表示式的概述

1 正規表示式 1 就是符合一定規則的字串 2 常見規則 a 字元 x 字元 x。舉例 a 表示字元a 反斜線字元。n 新行 換行 符 u000a r 回車符 u000d b 字元類 abc a b 或 c 簡單類 abc 任何字元,除了 a b 或 c 否定 a za z a到 z 或 a到 z,...