public class hiRegex extends Object
範囲解釈,グループ置き換えを強化した正規表現メソッド群を用意しました。
次の例では「関数名('a'...)」というパターンを「関数名_a(...)」に置き換えています。
import otsu.hiNote.*; public class Test{ public static void main(String[] args_){ try{ String _original="abc('a');def('b',2);int n=xyz('a',2,\"a\");if(ff('a',c)){...}"; String _result =hiRegex.with("(\\w+)\\s\*\('a',?([^)]*)\\)" // 正規表現パターン ,"${1}_a(${2})") // 置き換えパターン .replace(_original) // 置き換え対象文字列 .result(); // 結果を得る System.out.println("result="+_result); } catch(Exception _ex){ _ex.printStackTrace(System.err); System.exit(1); } } } ***結果 result=abc_a();def('b',2);int n=xyz_a(2,"a");if(ff_a(c)){...}
本クラスは置き換えを中心に置くものです。
単純にパターンを調べる場合はJavaのPattern
,Matcher
クラスを使います。
正規表現に関する基本説明
特殊文字 | 説明 | ||||||||||||||||||||||||||||||||||||||||||||||||
制御文字以外の単純文字列 |
制御文字以外の文字の並びは単純にその文字列とのマッチング検証となります。
hiRegex.replaceAll("abbx12-xy\n aBbX12xy-","12","###"); --> abbx###-xy <-- 12が###に置き換わった aBbX###xy- <-- 12が###に置き換わった次の文字は制御文字であるため、\(バックスラッシュまたは円マーク)でエスケープする必要があります。
|
||||||||||||||||||||||||||||||||||||||||||||||||
.(ドット) | 改行以外の任意の一文字 | ||||||||||||||||||||||||||||||||||||||||||||||||
^ | 領域の先頭を表します。 | ||||||||||||||||||||||||||||||||||||||||||||||||
$ | 領域の最後を表します。 | ||||||||||||||||||||||||||||||||||||||||||||||||
[文字集合] |
[]内のどれか一文字(制御文字を含む)
hiRegex.replaceAll("abbx12-xy\n aBbX12xy-","[aAx ]","#"); --> #bb#12-#y <-- aAxがそれぞれ#に置き換わった ##BbX12##Y <-- 空白も#に置き換わった |
||||||||||||||||||||||||||||||||||||||||||||||||
\に続く一文字(\wなど) |
\に続き特定のキー文字を書くと、いくつかの文字集合を表す、文字クラスとなります。 次のものです。
|
||||||||||||||||||||||||||||||||||||||||||||||||
\\u |
unicode4バイトを直接記述します | ||||||||||||||||||||||||||||||||||||||||||||||||
* |
一つ前の文字の0個以上の繰り返し。(最長一致) 前後のパターンも含めた最長一致となります。例えば、次の例ではbbxがマッチしますが、それより長いbbx123xもマッチしますのでbbx123xが採用されます。 hiRegex.replaceAll("abbx12-xy\n aBbX12xy-","b.*x","###"); --> a###y <-- bbx123xが置き換わった。(bxもマッチするが短い) AB###Y ================= hiRegex.replaceAll("abbx12-xy\n aBbX12xy-","12x*","###"); abbx###-xy <-- 12の後xは0個であるがマッチし12が置き換わった aBbX###y- <-- 12の後Axが1個でマッチし12xが置き換わった ================= (参考;よく知られたjava-Stringの問題点) "abbx12-xy\n aBbX12xy-".replaceAll(".*","###"); --> ###### <-- abbx12-xyがマッチした後、長さ0のマッチがあり、その後に改行 ###### |
||||||||||||||||||||||||||||||||||||||||||||||||
*? |
一つ前の文字の0個以上の繰り返し。(後方最短一致) 前後のパターンも含めた最長一致となります。例えば、次の例ではbbxもbxもマッチしますが、開始位置をずらしての最短を採ることはなくbbxが採用されます。 .は改行を含まないので次の行にあるaBbX12xy-のxは対象外です。 hiRegex.replaceAll("abbx12-xy\n aBbX12xy-","b.*x","###"); --> a###12-xy <-- bbxが置き換わった。(bxもマッチするが開始位置をずらしての検証はない) AB###Y |
||||||||||||||||||||||||||||||||||||||||||||||||
+ | 一つ前の文字の+個以上の繰り返し。 | ||||||||||||||||||||||||||||||||||||||||||||||||
? | 直前の文字は省略可能 | ||||||||||||||||||||||||||||||||||||||||||||||||
{数} | 直前の文字の指定個の繰り返し | ||||||||||||||||||||||||||||||||||||||||||||||||
前置式、後置式 (?<=...):肯定前置 (?<!...):否定前置 (?=...):肯定後置 (?!...):否定後置 |
当該パターンの前後にあるべきパターン、またはあってはならないパターンを指定します。 前置、後置パターン自体は当該パターンに含まれないものとなります。 例えば次の例の「単語」では前後に単語を構成する以外の文字が必要ですが、それらは「単語」には含まれません。 (?<!\w)\w+(?!\w) : 単語(前後を単語以外の文字で囲まれている。前置後置はパターン全体から見て内部に置くこともできます。 例えば次の例のhtmlタグでは(a|br....)の後ろに単語以外の文字が後置され、さらにその後ろにパターンが続きます。
</?(a|br|div|p|pre)(?=\W)[^>\n]*> : htmlのタグ(この例では一部載せてある,実際にはtable他あり)
|
構造化正規表現
hiRegexは単純な正規表現だけではなく、hiProperty
を用い構造化された正規表現を取り扱います。
構造化正規表現は次の特徴を持ちます。
例えば、開始パターンと終了パターンを示しその中だけでマッチングを行うといったことができます。
またマッチングした部分を単純に置き換えるのではなく、ラムダ関数に引き渡したり、あるいはファイルを読んで置き換えたりもできます。
基本手続き(一関数完結とカスケード式)
2種類の使用方法があります。
Javaで用意されているメソッドとの比較
Javaで用意されているPattern
とMatcher
を用いた操作の例とhiRegexを用いた例を載せます。
--- API ---
修飾子とタイプ | クラスと説明 |
---|---|
static class |
hiRegex.ExclusiveKeyException |
static class |
hiRegex.FormatException |
static class |
hiRegex.IllegalSequenceException |
static class |
hiRegex.MissingParamException |
static class |
hiRegex.MultipledKeyException |
static class |
hiRegex.NotYetSupporedException |
static class |
hiRegex.Parameter |
修飾子とタイプ | フィールドと説明 |
---|---|
static String |
EOL
single_regionでの行末パターン
|
static String |
SOL
single_regionでの行先頭パターン
|
修飾子とタイプ | メソッドと説明 |
---|---|
static boolean |
matches(String text_,
String regex_)
完全一致するか調べる
|
static String |
re(char escape_char_,
String text_)
正規表現上の"\"を別文字で与える.
|
static String[] |
re(char escape_char_,
String[] texts_)
正規表現上の"\"を別文字で与える.
|
hiRegex |
read(String fileName_)
指定ファイルを読み込み置き換える.
|
hiRegex |
replace(String text_)
指定文字列を置き換える.
|
static String |
replaceAll(String original_text_,
hiProperty prop_)
hiPropertyで示されるパターンにそって置き換える.
|
static String |
replaceAll(String original_text_,
hiProperty prop_,
hiU.BiFunctionEx<String,Matcher,String,Exception> func_)
hiPropertyで示されるパターンにそって置き換える.
|
static String |
replaceAll(String original_text_,
hiProperty prop_,
hiU.FunctionEx<String,String,Exception> func_)
hiPropertyで示されるパターンにそって置き換える.
|
static String |
replaceAll(String original_text_,
hiProperty prop_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> func_)
hiPropertyで示されるパターンにそって置き換える.
|
static String |
replaceAll(String text_,
Pattern pattern_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
hiU.FunctionEx<String,String,Exception> strFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
hiU.FunctionEx<String,String,Exception> strFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_)
正規表現でマッチする部分を置き換え.
|
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_) |
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
hiU.FunctionEx<String,String,Exception> strFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
hiU.FunctionEx<String,String,Exception> strFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_) |
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
Pattern pattern_,
String replacement_,
long option_)
正規表現でマッチする部分を置き換え.
|
static String |
replaceAll(String text_,
String regex_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
hiU.FunctionEx<String,String,Exception> strFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
hiU.FunctionEx<String,String,Exception> strFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
String replacement_)
正規表現でマッチする部分を置き換え.
|
static String |
replaceAll(String text_,
String regex_,
String replacement_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_) |
static String |
replaceAll(String text_,
String regex_,
String replacement_,
hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
String replacement_,
hiU.FunctionEx<String,String,Exception> strFunc_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
String replacement_,
hiU.FunctionEx<String,String,Exception> strFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
String replacement_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_) |
static String |
replaceAll(String text_,
String regex_,
String replacement_,
hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_,
long option_)
正規表現でマッチする部分を置き換え(ラムダ式使用).
|
static String |
replaceAll(String text_,
String regex_,
String replacement_,
long option_)
正規表現でマッチする部分を置き換え.
|
static String |
reQ(char escape_char_,
String text_)
正規表現上の"\"を別文字で与え,'を"に置き換える.
|
static String[] |
reQ(char escape_char_,
String[] texts_)
正規表現上の"\"を別文字で与え,'を"に置き換える.
|
String |
result()
置き換え結果を取得する
|
hiRegex |
result(StringBuilder sb_)
置き換え結果を取得する.
outputの結果とreplaceの結果をそれぞれ取得します。
|
hiRegex |
set_source_name(String sourceName_) |
hiRegex |
with_line_separator(String lineSeparator_)
最終結果の改行コードを指定のものにする.
|
hiRegex |
with_source_name(String sourceName_)
${_SOURCE_}で得られる名前をセットする
|
static hiRegex |
with(char alt_char_,
String regex_str_,
String replacement_str_)
逆スラッシュ代替文字,正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
with(File propFile_)
定義をファイルからセットする.
|
static hiRegex |
with(hiProperty prop_)
hiPropertyからセットする.
|
static hiRegex |
with(hiProperty prop_,
hiRegex entry_)
hiPropertyからセットする.
|
static hiRegex |
with(Pattern pattern_)
正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
with(Pattern pattern_,
String replacement_str_)
正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
with(String regex_str_,
String replacement_str_) |
static hiRegex |
withFile(String propFileName_)
指定定義ファイルにより変換準備のできたhiRegexを得る.
|
hiRegex |
withFunction(hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
マッチ部の通知を受けるラムダ関数追加.
|
hiRegex |
withFunction(hiU.FunctionEx<String,String,Exception> strFunc_)
マッチ部の通知を受けるラムダ関数追加.
|
hiRegex |
withFunction(hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> paramFunc_)
マッチ部の通知を受けるラムダ関数追加.
|
hiRegex |
withOption(long option_)
正規表現文字列と置き換え文字列による定義にオプションを追加する.
|
hiRegex |
withPrinter(PrintWriter pw_)
printでの出力先を設定する.
|
hiRegex |
withProgress(PrintStream ps_,
int interval_)
進行状態を表示する
|
hiRegex |
withProgress(PrintWriter pw_,
int interval_)
進行状態を表示する
|
static hiRegex |
withPropFile(String propFileName_)
定義をファイルからセットする.
|
static hiRegex |
withQ(char alt_char_,
String regex_str_,
String replacement_str_)
逆スラッシュ代替文字,正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
withRegex(char escape_,
String regex_str_)
正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
withRegex(char escape_,
String regex_str_,
String replacement_str_)
正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
withRegex(String regex_str_)
正規表現文字列と置き換え文字列からセットする.
|
static hiRegex |
withRegex(String regex_str_,
String replacement_str_)
正規表現文字列と置き換え文字列からセットする.
|
hiRegex |
write(String fileName_)
指定ファイルを置き換え対象文字列として読み込む.
|
public static hiRegex withPropFile(String propFileName_)
propFileName_
- 定義ファイル名public static hiRegex with(File propFile_)
propFile_
- 定義ファイルpublic static hiRegex with(hiProperty prop_)
prop_
- 定義ファイル名public static hiRegex with(hiProperty prop_, hiRegex entry_)
prop_
- 定義ファイル名entry_
- 入り口のhiRegexpublic static hiRegex withRegex(String regex_str_, String replacement_str_)
regex_str_
- 正規表現replacement_str_
- 置き換え文字列public static hiRegex withRegex(char escape_, String regex_str_, String replacement_str_)
escape_
- 正規表現エスケープ文字regex_str_
- 正規表現(逆スラッシュの代わりにescapeを使った表現)replacement_str_
- 置き換え文字列public static hiRegex withRegex(String regex_str_)
regex_str_
- 正規表現public static hiRegex withRegex(char escape_, String regex_str_)
escape_
- 正規表現エスケープ文字regex_str_
- 正規表現(逆スラッシュの代わりにescapeを使った表現)public static hiRegex with(Pattern pattern_, String replacement_str_)
pattern_
- 正規表現replacement_str_
- 置き換え文字列public static hiRegex with(Pattern pattern_)
pattern_
- 正規表現public static hiRegex with(char alt_char_, String regex_str_, String replacement_str_)
リテラル正規表現文字列内の逆ラッシュを別文字で代替します。
hiRegex.with("(\\w+)\\s\*\('a',?([^)]*)\\)" // 正規表現パターン ,"${1}_a(${2})") // 置き換えパターン の代わりに hiRegex.with('%' // 代理文字 ,"(%w+)%s*%('a',?([^)]*)%)" // 正規表現パターン ,"${1}_a(${2})") // 置き換えパターン
内容と衝突しない限り置き換え文字に制約はありません。通常正規表現との衝突の無い%#/の何れかを使います。
この文字自体のエスケープはありません。
alt_char_
- 逆スラッシュ代替文字regex_str_
- 正規表現replacement_str_
- 置き換え文字列public static hiRegex withQ(char alt_char_, String regex_str_, String replacement_str_)
リテラル正規表現文字列内の逆ラッシュを別文字で代替しダブルクオートをシングルクオートで代替します。
alt_char_
- 逆スラッシュ代替文字regex_str_
- 正規表現replacement_str_
- 置き換え文字列public hiRegex withOption(long option_)
次のオプションが追加できます。
option_
- オプションpublic hiRegex withFunction(hiU.FunctionEx<String,String,Exception> strFunc_)
ラムダ関数は
strFunc_
- 関数public hiRegex withFunction(hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
ラムダ関数は
matFunc_
- 関数public hiRegex withFunction(hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> paramFunc_)
ラムダ関数は
hiRegex.Parameter
です。paramFunc_
- 関数public hiRegex withPrinter(PrintWriter pw_)
pw_
- 出力先public hiRegex withProgress(PrintWriter pw_, int interval_)
pw_
- 出力先interval_
- 出力間隔public hiRegex withProgress(PrintStream ps_, int interval_)
ps_
- 出力先 (System.errなど)interval_
- 出力間隔public hiRegex read(String fileName_)
次のような形で使います。
String _result= hiRegex.withProp("prop.txt") // 方式定義ファイル取り込み .read("in.txt") // 対象文字列ファイル指定 .result(); // 結果取得
ファイルの文字コードはどちらもutf-8です。
fileName_
- ファイル名public hiRegex replace(String text_)
次のような形で使います。
String _src = "...";// 置き換え対象文字列 String _result= hiRegex.withProp("prop.txt") // 方式定義ファイル取り込み .replace_literal(_src) // 対象文字列ファイル指定 .result(); // 結果取得
ファイルの文字コードはどちらもutf-8です。
text_
- 置き換え対象文字列public String result()
public hiRegex result(StringBuilder sb_)
sb_
- replace結果を追加するStringBuilderpublic hiRegex write(String fileName_)
次のような形で使います。
hiRegex.withProp("prop.txt") // 方式定義ファイル指定 .read("in.txt") // 対象文字列ファイル指定 .write("out.txt"); // 置き換えを実行し指定ファイルに出力
ファイルの文字コードはどちらもutf-8です。
fileName_
- ファイル名public static String replaceAll(String original_text_, hiProperty prop_, hiU.FunctionEx<String,String,Exception> func_)
hiProperty
で与えられる構造化正規表現によって文字列の置き換えを行います。original_text_
- 変換対象prop_
- パターンfunc_
- ラムダ関数public static String replaceAll(String original_text_, hiProperty prop_, hiU.BiFunctionEx<String,Matcher,String,Exception> func_)
hiProperty
で与えられる構造化正規表現によって文字列の置き換えを行います。original_text_
- 変換対象prop_
- パターンfunc_
- ラムダ関数public static String replaceAll(String original_text_, hiProperty prop_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> func_)
original_text_
- 変換対象prop_
- パターンfunc_
- ラムダ関数public static String replaceAll(String original_text_, hiProperty prop_)
hiProperty
で与えられる構造化正規表現によって文字列の置き換えを行います。original_text_
- 変換対象prop_
- パターンpublic static String replaceAll(String text_, String regex_, String replacement_, long option_)
text_
- 変換対象regex_
- 変換場所を示す正規表現replacement_
- 置き換え文字列option_
- オプション hiU.NO_GROUP hiU.IGNORE_CASE hiU.LITERAL hiU.SIMGLE_REGIONpublic static String replaceAll(String text_, Pattern pattern_, String replacement_, long option_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現replacement_
- 置き換え文字列option_
- オプション hiU.NO_GROUP hiU.IGNORE_CASE hiU.LITERAL hiU.SIMGLE_REGIONpublic static String replaceAll(String text_, String regex_, String replacement_)
text_
- 変換対象regex_
- 変換場所を示す正規表現replacement_
- 置き換え文字列public static String replaceAll(String text_, Pattern pattern_, String replacement_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現replacement_
- 置き換え文字列public static String replaceAll(String text_, String regex_, hiU.FunctionEx<String,String,Exception> strFunc_, long option_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象regex_
- 変換場所を示す正規表現strFunc_
- Stringを引数とする置き換えラムダ式option_
- オプション hiU.NO_GROUP hiU.IGNORE_CASE hiU.LITERAL hiU.SIMGLE_REGIONpublic static String replaceAll(String text_, Pattern pattern_, hiU.FunctionEx<String,String,Exception> strFunc_, long option_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象pattern_
- 変換場所を示す正規表現strFunc_
- Stringを引数とする置き換えラムダ式option_
- オプション hiU.NO_GROUP hiU.IGNORE_CASE hiU.LITERAL hiU.SIMGLE_REGIONpublic static String replaceAll(String text_, String regex_, hiU.FunctionEx<String,String,Exception> strFunc_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象regex_
- 変換場所を示す正規表現strFunc_
- Stringを引数とする置き換えラムダ式public static String replaceAll(String text_, Pattern pattern_, hiU.FunctionEx<String,String,Exception> strFunc_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象pattern_
- 変換場所を示す正規表現strFunc_
- Stringを引数とする置き換えラムダ式public static String replaceAll(String text_, String regex_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_, long option_)
text_
- 変換対象regex_
- 変換場所を示す正規表現matFunc_
- String,Matcherを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, Pattern pattern_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_, long option_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現matFunc_
- String,Matcherを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, String regex_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
text_
- 変換対象regex_
- 変換場所を示す正規表現matFunc_
- String,Matcherを引数とする置き換えラムダ式public static String replaceAll(String text_, Pattern pattern_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現matFunc_
- String,Matcherを引数とする置き換えラムダ式public static String replaceAll(String text_, String regex_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_, long option_)
text_
- 変換対象regex_
- 変換場所を示す正規表現matFunc_
- String,Matcher,Parameterを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, Pattern pattern_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_, long option_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現matFunc_
- String,Matcher,Parameterを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, String regex_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_)
text_
- 変換対象regex_
- 変換場所を示す正規表現matFunc_
- String,Matcher,Parameterを引数とする置き換えラムダ式public static String replaceAll(String text_, Pattern pattern_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現matFunc_
- String,Matcher,Parameterを引数とする置き換えラムダ式public static String replaceAll(String text_, String regex_, String replacement_, hiU.FunctionEx<String,String,Exception> strFunc_, long option_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象regex_
- 変換場所を示す正規表現replacement_
- 置き換え文字列strFunc_
- Stringを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, Pattern pattern_, String replacement_, hiU.FunctionEx<String,String,Exception> strFunc_, long option_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象pattern_
- 変換場所を示す正規表現replacement_
- 置き換え文字列strFunc_
- Stringを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, String regex_, String replacement_, hiU.FunctionEx<String,String,Exception> strFunc_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象regex_
- 変換場所を示す正規表現replacement_
- 置き換え文字列strFunc_
- Stringを引数とする置き換えラムダ式public static String replaceAll(String text_, Pattern pattern_, String replacement_, hiU.FunctionEx<String,String,Exception> strFunc_)
String.replaceAll(String,String)
と異なり、replacement_はグループ参照しません。
text_
- 変換対象pattern_
- 変換場所を示す正規表現replacement_
- 置き換え文字列strFunc_
- Stringを引数とする置き換えラムダ式public static String replaceAll(String text_, String regex_, String replacement_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_, long option_)
text_
- 変換対象regex_
- 変換場所を示す正規表現replacement_
- 置き換え文字列matFunc_
- String,Matcherを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, String regex_, String replacement_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
public static String replaceAll(String text_, Pattern pattern_, String replacement_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_, long option_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現replacement_
- 置き換え文字列matFunc_
- String,Matcherを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, Pattern pattern_, String replacement_, hiU.BiFunctionEx<String,Matcher,String,Exception> matFunc_)
public static String replaceAll(String text_, String regex_, String replacement_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_, long option_)
text_
- 変換対象regex_
- 変換場所を示す正規表現replacement_
- 置き換え文字列matFunc_
- String,Matcher,Parameterを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, String regex_, String replacement_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_)
public static String replaceAll(String text_, Pattern pattern_, String replacement_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_, long option_)
text_
- 変換対象pattern_
- 変換場所を示す正規表現replacement_
- 置き換え文字列matFunc_
- String,Matcher,Parameterを引数とする置き換えラムダ式option_
- オプションpublic static String replaceAll(String text_, Pattern pattern_, String replacement_, hiU.TriFunctionEx<String,Matcher,hiRegex.Parameter,String,Exception> matFunc_)
public static boolean matches(String text_, String regex_)
text_
- テキストregex_
- 正規表現public static String re(char escape_char_, String text_)
正規表現文字列をプログラムソース上に書く場合の"\"の扱いのわずらわしさを避けるためのものです。
// 与えたい正規表現 set\s*:\s*\(\s*(\w+)\s*\) set : ( ABC ) など String _regex= "set\\s*:\\s\*\(\\s*(\\w+)\\s\*\)"; String _regex= hiRegex.re('!',"set!s*:!s*!(!s*(!w+)!s*!)"); // 与えたい文字列 set\s\*\\s*"(\w+)" set \ "ABC" など String _regex= "set\\s\*\\\\\s*\"(\\w+)\""; String _regex= hiRegex.re('!',"set!s*!!!s*\"(!w+)\"");
escape_char_
- エスケープ文字text_
- 正規表現用の文字列public static String reQ(char escape_char_, String text_)
正規表現文字列をプログラムソース上に書く場合の"\"の扱いのわずらわしさを避けるためのものです。
// 与えたい正規表現 set\s*:\s*\(\s*(\w+)\s*\) set : ( ABC ) など String _regex= "set\\s*:\\s\*\(\\s*(\\w+)\\s\*\)"; String _regex= hiRegex.re('!',"set!s*:!s*!(!s*(!w+)!s*!)"); // 与えたい文字列 set\s\*\\s*"(\w+)" set \ "ABC" など String _regex= "set\\s\*\\\\\s*\"(\\w+)\""; String _regex= hiRegex.re('!',"set!s*!!!s*\"(!w+)\"");
escape_char_
- エスケープ文字text_
- 正規表現用の文字列public static String[] re(char escape_char_, String[] texts_)
escape_char_
- エスケープ文字texts_
- 正規表現用の文字列の配列(変更されない)public static String[] reQ(char escape_char_, String[] texts_)
escape_char_
- エスケープ文字texts_
- 正規表現用の文字列の配列(変更されない)public static hiRegex withFile(String propFileName_)
propFileName_
- 定義ファイル名public hiRegex with_source_name(String sourceName_)
sourceName_
- ソース名