regex

170
正規表現

Upload: kmiyako

Post on 19-Jun-2015

429 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Regex

正規表現

Page 2: Regex

正規表現

Page 3: Regex

正規表現

あらゆるパターンを列挙せずに文字列群を簡潔に表現

Page 4: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

Page 5: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

Page 6: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode

http://shapecatcher.com/unicode/block/Katakana.html

Page 7: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F834 ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク グ835 ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ ダ836 チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ バ837 パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ838 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ839 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Shift_JIS

Page 8: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode

http://shapecatcher.com/unicode/block/Katakana.html

Page 9: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode KATAKANA-HIRAGANA DOUBLE HYPHEN

Page 10: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode KATAKANA MIDDLE DOT

Page 11: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode KATAKANA-HIRAGANA PROLONGED SOUND MARK

Page 12: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode KATAKANA ITERATION MARK

Page 13: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode KATAKANA VOICED ITERATION MARK

Page 14: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode KATAKANA DIGRAPH KOTO

Page 15: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode

Page 16: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

0 1 2 3 4 5 6 7 8 9 A B C D E F30A0 ゠ ァ ア ィ イ ゥ ウ ェ エ ォ オ カ ガ キ ギ ク30B0 グ ケ ゲ コ ゴ サ ザ シ ジ ス ズ セ ゼ ソ ゾ タ30C0 ダ チ ヂ ッ ツ ヅ テ デ ト ド ナ ニ ヌ ネ ノ ハ30D0 バ パ ヒ ビ ピ フ ブ プ ヘ ベ ペ ホ ボ ポ マ ミ30E0 ム メ モ ャ ヤ ュ ユ ョ ヨ ラ リ ル レ ロ ヮ ワ30F0 ヰ ヱ ヲ ン ヴ ヵ ヶ ヷ ヸ ヹ ヺ ・ ー ヽ ヾ ヿ

Unicode

1文字ずつコードを比較していたら大変・・・

Page 17: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

Page 18: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

$regex:="[\\u30A0-\\u30FF]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

Page 19: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

$regex:="[\\u30A0-\\u30FF]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

文字コードが合致

Page 20: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

$regex:="[\\u30A0-\\u30FF]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

Page 21: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

$regex:="[:Katakana:]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

Page 22: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

$regex:="[:Katakana:]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

プロパティが合致

Page 23: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

カタカナEx. 1

$regex:="[:Katakana:]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

Page 24: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

半角カタカナEx. 2

$regex:="[:East Asian Width=Halfwidth:]+"

$yomi:="ミヤコケイスケ"

$match:=Match regex($regex;$yomi)

Page 25: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

漢字Ex. 3

$regex:="[:Ideographic:]+"

$name:="宮古啓介"

$match:=Match regex($regex;$name)

Page 26: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

英数Ex. 4

$regex:="[:East Asian Width=Narrow:]+"

$user:="miyako0922"ス

$match:=Match regex($regex;$user)

Page 27: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

電子メールアドレスEx. 5

Page 28: Regex

正規表現あらゆるパターンを列挙せずに文字列群を簡潔に表現

http://www.w3.org/TR/html5-author/states-of-the-type-attribute.html#e-mail-state-(type=email)

電子メールアドレスEx. 5

$regex:="^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+\ @[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"

$address:="[email protected]"ス

$match:=Match regex($regex;$address)

Page 29: Regex

正規表現

Page 30: Regex

正規表現使用する理由

Page 31: Regex

正規表現

一般

使用する理由

Page 32: Regex

正規表現

‣文字列処理の標準ツール(構文・ライブラリで提供)一般

使用する理由

Page 33: Regex

正規表現

‣文字列処理の標準ツール(構文・ライブラリで提供)‣既存のソリューションが豊富

一般

使用する理由

Page 34: Regex

正規表現

‣文字列処理の標準ツール(構文・ライブラリで提供)‣既存のソリューションが豊富

一般

4D

使用する理由

Page 35: Regex

正規表現

‣文字列処理の標準ツール(構文・ライブラリで提供)‣既存のソリューションが豊富

‣包括的( c.f. Character code)

一般

4D

使用する理由

Page 36: Regex

正規表現

‣文字列処理の標準ツール(構文・ライブラリで提供)‣既存のソリューションが豊富

‣包括的( c.f. Character code)

‣厳格(c.f. Position,=,#)

一般

4D

使用する理由

Page 37: Regex

Match regex

Page 38: Regex

Match regex構文

Page 39: Regex

Match regex構文

1/7

Page 40: Regex

Match regex構文

1/7

C_TEXT($regex;$string)C_BOOLEAN($match)

$match:=Match regex($regex;$string)

Page 41: Regex

Match regex構文

1/7

C_TEXT($regex;$string)C_BOOLEAN($match)

$match:=Match regex($regex;$string)

$stringが$regexにピッタリ合致すればTrue

Page 42: Regex

Match regex構文

2/7

Page 43: Regex

Match regex構文

2/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)

$match:=Match regex($regex;$string;$start)

Page 44: Regex

Match regex構文

2/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)

$match:=Match regex($regex;$string;$start)

$stringが$regexに$start以降で合致すればTrue

Page 45: Regex

Match regex構文

3/7

Page 46: Regex

Match regex構文

3/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)

$match:=Match regex($regex;$string;$start;*)

Page 47: Regex

Match regex構文

3/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)

$match:=Match regex($regex;$string;$start;*)

$stringが$regexに$startでピッタリ合致すればTrue

Page 48: Regex

Match regex構文

4/7

Page 49: Regex

Match regex構文

4/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start;$pos;$len)

$match:=Match regex($regex;$string;$start;$pos;$len)

Page 50: Regex

Match regex構文

4/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start;$pos;$len)

$match:=Match regex($regex;$string;$start;$pos;$len)

$stringが$regexに$start以降で合致すればTrue

Page 51: Regex

Match regex構文

4/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start;$pos;$len)

$match:=Match regex($regex;$string;$start;$pos;$len)

$len: 合致した文字数

$pos: 合致した位置

$stringが$regexに$start以降で合致すればTrue

Page 52: Regex

Match regex構文

5/7

Page 53: Regex

Match regex構文

5/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start;$pos;$len)

$match:=Match regex($regex;$string;$start;$pos;$len;*)

Page 54: Regex

Match regex構文

5/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start;$pos;$len)

$match:=Match regex($regex;$string;$start;$pos;$len;*)

$stringが$regexに$startでピッタリ合致すればTrue

Page 55: Regex

Match regex構文

5/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start;$pos;$len)

$match:=Match regex($regex;$string;$start;$pos;$len;*)

$len: 合致した文字数

$pos: 合致した位置

$stringが$regexに$startでピッタリ合致すればTrue

Page 56: Regex

Match regex構文

6/7

Page 57: Regex

Match regex構文

6/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)

$match:=Match regex($regex;$string;$start;$pos;$len)

Page 58: Regex

Match regex構文

6/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)

$match:=Match regex($regex;$string;$start;$pos;$len)

$stringが$regexに$start以降で合致すればTrue

Page 59: Regex

Match regex構文

6/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)

$match:=Match regex($regex;$string;$start;$pos;$len)

$stringが$regexに$start以降で合致すればTrue

$len: グループ毎の合致した文字数

$pos: グループ毎の合致した位置

Page 60: Regex

Match regex構文

7/7

Page 61: Regex

Match regex構文

7/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)

$match:=Match regex($regex;$string;$start;$pos;$len;*)

Page 62: Regex

Match regex構文

7/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)

$match:=Match regex($regex;$string;$start;$pos;$len;*)

$stringが$regexに$startでピッタリ合致すればTrue

Page 63: Regex

Match regex構文

7/7

C_TEXT($regex;$string)C_BOOLEAN($match)C_LONGINT($start)ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)

$match:=Match regex($regex;$string;$start;$pos;$len;*)

$stringが$regexに$startでピッタリ合致すればTrue

$len: グループ毎の合致した文字数

$pos: グループ毎の合致した位置

Page 64: Regex

正規表現

Page 65: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

Page 66: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

\A 入力の始まり \d 数字 \x 文字を2桁16進で指定\z 入力の終わり \D 数字ではない \u 文字を4桁16進で指定

\Z 入力の終わり* \p プロパティ有 \U 文字を8桁16進で指定

\b ワードの区切り \P プロパティ無 \0 文字を3桁で8進で指定

\B ワードの区切りではない \s 空白 \N 文字を名前で指定

\a ベル(U+0007) \S 空白ではない \1 捕捉したグループの参照

\t TAB(U+0009) \w ワード文字 \G パターンの後わり\e ESC(U+001B) \W ワード文字ではない . 文字\r CR(U+000D) \Q エスケープシーケンス始 ^ 行の始まり\f FF(U+000C) \E エスケープシーケンス終 $ 行の終わり\n LF(U+000A) \X グラフィームクラスター \ 後続の文字をエスケープ

*端末文字は含まない

Page 67: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

\A 入力の始まり \d 数字 \x 文字を2桁16進で指定\z 入力の終わり \D 数字ではない \u 文字を4桁16進で指定

\Z 入力の終わり* \p プロパティ有 \U 文字を8桁16進で指定

\b ワードの区切り \P プロパティ無 \0 文字を3桁で8進で指定

\B ワードの区切りではない \s 空白 \N 文字を名前で指定

\a ベル(U+0007) \S 空白ではない \1 捕捉したグループの参照

\t TAB(U+0009) \w ワード文字 \G パターンの後わり\e ESC(U+001B) \W ワード文字ではない . 文字\r CR(U+000D) \Q エスケープシーケンス始 ^ 行の始まり\f FF(U+000C) \E エスケープシーケンス終 $ 行の終わり\n LF(U+000A) \X グラフィームクラスター \ 後続の文字をエスケープ

*端末文字は含まない

basic

Page 68: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

\A 入力の始まり \d 数字 \x 文字を2桁16進で指定\z 入力の終わり \D 数字ではない \u 文字を4桁16進で指定

\Z 入力の終わり* \p プロパティ有 \U 文字を8桁16進で指定

\b ワードの区切り \P プロパティ無 \0 文字を3桁で8進で指定

\B ワードの区切りではない \s 空白 \N 文字を名前で指定

\a ベル(U+0007) \S 空白ではない \1 捕捉したグループの参照

\t TAB(U+0009) \w ワード文字 \G パターンの後わり\e ESC(U+001B) \W ワード文字ではない . 文字\r CR(U+000D) \Q エスケープシーケンス始 ^ 行の始まり\f FF(U+000C) \E エスケープシーケンス終 $ 行の終わり\n LF(U+000A) \X グラフィームクラスター \ 後続の文字をエスケープ

*端末文字は含まない

advanced

Page 69: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

. 文字

$regex:="Column."$string:="ColumnA"$match:=Match regex($regex;$string)

Page 70: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

True

. 文字

$regex:="Column."$string:="ColumnA"$match:=Match regex($regex;$string)

Page 71: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d"$string:="Column2"$match:=Match regex($regex;$string)

\d 数字

Page 72: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d"$string:="Column2"$match:=Match regex($regex;$string)

True

\d 数字

Page 73: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d"$string:="Column1"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

\d 数字

Page 74: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d"$string:="Column1"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

\d 数字

True

Page 75: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d"$string:="Column1"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

1

\d 数字

True

Page 76: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\s\\d"$string:="Column 2"$match:=Match regex($regex;$string)

\s 空白

Page 77: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\s\\d"$string:="Column 2"$match:=Match regex($regex;$string)

True

\s 空白

Page 78: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\s\\d"$string:="Column 2"$match:=Match regex($regex;$string)

True

\s 空白

\s: [\t\n\f\r\p{Z}] 全角スペース タブ 改行 その他 [:Separator:]

Page 79: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\u0001"$string:="Column"+Char(1)$match:=Match regex($regex;$string)

\u 文字を4桁16進で指定

Page 80: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\u0001"$string:="Column"+Char(1)$match:=Match regex($regex;$string)

True

\u 文字を4桁16進で指定

Page 81: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="^Column\\d"$string:=" Column1"$match:=Match regex($regex;$string;1)

^ 行の始まり

Page 82: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="^Column\\d"$string:=" Column1"$match:=Match regex($regex;$string;1)

False

^ 行の始まり

Page 83: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d$"$string:="Column1 "$match:=Match regex($regex;$string;1)

$ 行の終わり

Page 84: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d$"$string:="Column1 "$match:=Match regex($regex;$string;1)

False

$ 行の終わり

Page 85: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d\\.\\d"$string:="Column1.2"$match:=Match regex($regex;$string;1)

\ 後続の文字をエスケープ

Page 86: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d\\.\\d"$string:="Column1.2"$match:=Match regex($regex;$string;1)

\ 後続の文字をエスケープ

エスケープが必要な文字: * ? + [ ( ) { } ^ $ | \ .

Page 87: Regex

正規表現メタ文字

http://userguide.icu-project.org/strings/regexp

basic

$regex:="Column\\d\\.\\d"$string:="Column1.2"$match:=Match regex($regex;$string;1)

\ 後続の文字をエスケープ

エスケープが必要な文字: * ? + [ ( ) { } ^ $ | \ .

True

Page 88: Regex

正規表現

Page 89: Regex

正規表現演算子

http://userguide.icu-project.org/strings/regexp

Page 90: Regex

正規表現演算子

http://userguide.icu-project.org/strings/regexp

| パターンの論理和【OR】 {n} n個ピッタリ

* 0個以上,できるだけ多く【控えめ】 {n,} n個以上,できるだけ多く【控えめ】

+ 1個以上,できるだけ多く【控えめ】 {n,m} n個以上,m個以下,できるだけ多く【控えめ】

*+ 0個以上,できるだけ多く【欲張り】 {n,} n個以上,できるだけ多く【欲張り】

++ 1個以上,できるだけ多く【欲張り】 {n,m} n個以上,m個以下,できるだけ多く【 欲張り】

*? 0個以上,できるだけ少なく (...) 捕捉するグループ

+? 1個以上,できるだけ少なく (?:...) 捕捉しないグループ

? 1個以下,できれば1個【控えめ】 (?=...) 先読みアサーション

?+ 1個以下,できれば1個【欲張り】 (?!...) 否定先読みアサーション

?? 1個以下,できれば0個 (?<=...) 後読みアサーション

(?#...) コメント (?<!...) 否定後読みアサーション

Page 91: Regex

正規表現演算子

http://userguide.icu-project.org/strings/regexp

| パターンの論理和【OR】 {n} n個ピッタリ

* 0個以上,できるだけ多く【控えめ】 {n,} n個以上,できるだけ多く【控えめ】

+ 1個以上,できるだけ多く【控えめ】 {n,m} n個以上,m個以下,できるだけ多く【控えめ】

*+ 0個以上,できるだけ多く【欲張り】 {n,} n個以上,できるだけ多く【欲張り】

++ 1個以上,できるだけ多く【欲張り】 {n,m} n個以上,m個以下,できるだけ多く【 欲張り】

*? 0個以上,できるだけ少なく (...) 捕捉するグループ

+? 1個以上,できるだけ少なく (?:...) 捕捉しないグループ

? 1個以下,できれば1個【控えめ】 (?=...) 先読みアサーション

?+ 1個以下,できれば1個【欲張り】 (?!...) 否定先読みアサーション

?? 1個以下,できれば0個 (?<=...) 後読みアサーション

(?#...) コメント (?<!...) 否定後読みアサーション

basic

Page 92: Regex

正規表現演算子

http://userguide.icu-project.org/strings/regexp

| パターンの論理和【OR】 {n} n個ピッタリ

* 0個以上,できるだけ多く【控えめ】 {n,} n個以上,できるだけ多く【控えめ】

+ 1個以上,できるだけ多く【控えめ】 {n,m} n個以上,m個以下,できるだけ多く【控えめ】

*+ 0個以上,できるだけ多く【欲張り】 {n,} n個以上,できるだけ多く【欲張り】

++ 1個以上,できるだけ多く【欲張り】 {n,m} n個以上,m個以下,できるだけ多く【 欲張り】

*? 0個以上,できるだけ少なく (...) 捕捉するグループ

+? 1個以上,できるだけ少なく (?:...) 捕捉しないグループ

? 1個以下,できれば1個【控えめ】 (?=...) 先読みアサーション

?+ 1個以下,できれば1個【欲張り】 (?!...) 否定先読みアサーション

?? 1個以下,できれば0個 (?<=...) 後読みアサーション

(?#...) コメント (?<!...) 否定後読みアサーション

advanced

Page 93: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d+"$string:="123"$match:=Match regex($regex;$string)

演算子+ 1個以上,できるだけ多く【控えめ】

Page 94: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d+"$string:="123"$match:=Match regex($regex;$string)

演算子+ 1個以上,できるだけ多く【控えめ】

True

Page 95: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d+"$string:="-123"$match:=Match regex($regex;$string)

演算子+ 1個以上,できるだけ多く【控えめ】

Page 96: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d+"$string:="-123"$match:=Match regex($regex;$string)

演算子

False

+ 1個以上,できるだけ多く【控えめ】

Page 97: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="-?\\d+"$string:="-123"$match:=Match regex($regex;$string)

演算子? 1個以下,できれば1個【控えめ】

Page 98: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="-?\\d+"$string:="-123"$match:=Match regex($regex;$string)

True

演算子? 1個以下,できれば1個【控えめ】

Page 99: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="-|\\+\\d+"$string:="+123"$match:=Match regex($regex;$string)

演算子| パターンの論理和【OR】

Page 100: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="-|\\+\\d+"$string:="+123"$match:=Match regex($regex;$string)

True

演算子| パターンの論理和【OR】

Page 101: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="-?(?:\\d|,)+"$string:="-123,456"$match:=Match regex($regex;$string)

演算子(?:...) 捕捉しないグループ

Page 102: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="-?(?:\\d|,)+"$string:="-123,456"$match:=Match regex($regex;$string)

True

演算子(?:...) 捕捉しないグループ

Page 103: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="ID-\\d{6}"$string:="ID-123456"$match:=Match regex($regex;$string)

演算子{n} n個ピッタリ

Page 104: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="ID-\\d{6}"$string:="ID-123456"$match:=Match regex($regex;$string)

True

演算子{n} n個ピッタリ

Page 105: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d{4}-\\d{1,2}-\\d{1,2}"$string:="2013-1-13"$match:=Match regex($regex;$string)

演算子{n,m} n個以上,m個以下,できるだけ多く【控えめ】

Page 106: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic

$regex:="\\d{4}-\\d{1,2}-\\d{1,2}"$string:="2013-1-13"$match:=Match regex($regex;$string)

True

演算子{n,m} n個以上,m個以下,できるだけ多く【控えめ】

Page 107: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子* 0個以上,できるだけ多く【控えめ】

$regex:="Column\\d*"$string:="Column12345"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

Page 108: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子* 0個以上,できるだけ多く【控えめ】

$regex:="Column\\d*"$string:="Column12345"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

True

Page 109: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子* 0個以上,できるだけ多く【控えめ】

$regex:="Column\\d*"$string:="Column12345"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

Column12345True

Page 110: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+?:\\d+,??"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

+? 1個以上,できるだけ少なく【控えめ】

?? 1個以下,できれば0個【控えめ】

Page 111: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+?:\\d+,??"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

+? 1個以上,できるだけ少なく【控えめ】

?? 1個以下,できれば0個【控えめ】

True

Page 112: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+?:\\d+,??"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

tea:10

+? 1個以上,できるだけ少なく【控えめ】

?? 1個以下,できれば0個【控えめ】

True

Page 113: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+:\\d+,?"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

+ 1個以上,できるだけ多く【控えめ】

? 1個以下,できれば1個【控えめ】

Page 114: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+:\\d+,?"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

+ 1個以上,できるだけ多く【控えめ】

? 1個以下,できれば1個【控えめ】

True

Page 115: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+:\\d+,?"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

tea:10,coffee:4

+ 1個以上,できるだけ多く【控えめ】

? 1個以下,できれば1個【控えめ】

True

Page 116: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

basic演算子

$regex:=".+:\\d+,?"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

tea:10,coffee:4

+ 1個以上,できるだけ多く【控えめ】

? 1個以下,できれば1個【控えめ】

控えめ: 全体がマッチするのであれば最大数以下で満足する(数を減らして再評価)

True

Page 117: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

演算子

$regex:=".++:\\d+,?+"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

advanced

+ + 1個以上,できるだけ多く【欲張り】

?+ 1個以下,できれば1個【欲張り】

Page 118: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

演算子

$regex:=".++:\\d+,?+"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

advanced

+ + 1個以上,できるだけ多く【欲張り】

?+ 1個以下,できれば1個【欲張り】

False

Page 119: Regex

正規表現

http://userguide.icu-project.org/strings/regexp

演算子

$regex:=".++:\\d+,?+"$string:="tea:10,coffee:4"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

advanced

+ + 1個以上,できるだけ多く【欲張り】

?+ 1個以下,できれば1個【欲張り】

False

欲張り: 数を減らすことで全体がマッチするとしても取ったものは手放さない

Page 120: Regex

正規表現

Page 121: Regex

正規表現グループ

http://userguide.icu-project.org/strings/regexp

Page 122: Regex

正規表現グループ

http://userguide.icu-project.org/strings/regexp

ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)$regex:="(^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+)\ @([a-zA-Z0-9-]+)(\\.[a-zA-Z0-9-]+)*$"$string:="[email protected]"$match:=Match regex($regex;$string;1;$pos;$len)$group1:=Substring($string;$pos{1};$len{1})$group2:=Substring($string;$pos{2};$len{2})$group3:=Substring($string;$pos{3};$len{3})

Page 123: Regex

正規表現グループ

http://userguide.icu-project.org/strings/regexp

ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)$regex:="(^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+)\ @([a-zA-Z0-9-]+)(\\.[a-zA-Z0-9-]+)*$"$string:="[email protected]"$match:=Match regex($regex;$string;1;$pos;$len)$group1:=Substring($string;$pos{1};$len{1})$group2:=Substring($string;$pos{2};$len{2})$group3:=Substring($string;$pos{3};$len{3})

配列の要素数は捕捉グループ数に対応する

Page 124: Regex

正規表現グループ

http://userguide.icu-project.org/strings/regexp

ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)$regex:="(^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+)\ @([a-zA-Z0-9-]+)(\\.[a-zA-Z0-9-]+)*$"$string:="[email protected]"$match:=Match regex($regex;$string;1;$pos;$len)$group1:=Substring($string;$pos{1};$len{1})$group2:=Substring($string;$pos{2};$len{2})$group3:=Substring($string;$pos{3};$len{3})

配列の要素数は捕捉グループ数に対応する位置とサイズはそのままSubstringに渡すことができる

Page 125: Regex

正規表現グループ

http://userguide.icu-project.org/strings/regexp

ARRAY LONGINT($pos;0)ARRAY LONGINT($len;0)$regex:="(^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+)\ @([a-zA-Z0-9-]+)(\\.[a-zA-Z0-9-]+)*$"$string:="[email protected]"$match:=Match regex($regex;$string;1;$pos;$len)$group1:=Substring($string;$pos{1};$len{1})$group2:=Substring($string;$pos{2};$len{2})$group3:=Substring($string;$pos{3};$len{3})$group1 keisuke.miyako

$group2 4d

$group3 .com

配列の要素数は捕捉グループ数に対応する位置とサイズはそのままSubstringに渡すことができる

Page 126: Regex

正規表現

Page 127: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

Page 128: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

[BC] 列挙した文字のどれかに合致[^BC] 列挙した文字でなければ合致[B-D] 指定した範囲内の文字に合致(コードポイント順)

[:Letter:] プロパティで合致【POSIX表記】[\p{Letter}] プロパティで合致【Perl表記】

[\p{L}] プロパティで合致【Perl表記・短縮形】[\p{property=value}] プロパティと値で合致

[[:...:][:...:]] セットの集合結合【UNION】[[:...:]-[:...:]] セットの集合差異【DIFFERENCE】[[:...:]&[:...:]] セットの集合交差【INTERSECTION】[\\u0001] コードポイントに合致

[\\u0001-\\u0020] コードポイントの範囲に合致

Page 129: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[BC]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[BC] 列挙した文字のどれかに合致

Page 130: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[^BC]"$string:="sample.4DD"$match:=Match regex($regex;$string)

[^BC] 列挙した文字でなければ合致

Page 131: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[B-D]"$string:="sample.4DD"$match:=Match regex($regex;$string)

[B-D] 指定した範囲内の文字に合致(コードポイント順)

Page 132: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[:Letter:]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[:Letter:] プロパティで合致【POSIX表記】

Page 133: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[\\p{Letter}]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[\p{Letter}] プロパティで合致【Perl表記】

Page 134: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[\\p{L}]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[\p{L}] プロパティで合致【Perl表記・短縮形】

Page 135: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:="[\\p{numeric_value=9}]+"$string:="99九Ⅸⅸ⑨⑼⒐❾"$match:=Match regex($regex;$string)

[\p{property=value}] プロパティと値で合致

$regex:="[\\p{numeric_value=9}]+"$string:="abc"+char(9)$match:=Match regex($regex;$string)

Page 136: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[[:Letter:][:Number:]]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[[:...:][:...:]] セットの集合結合【UNION】

Page 137: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[[:Letter:]-[:Number:]]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[[:...:]-[:...:]] セットの集合差異【DIFFERENCE】

Page 138: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[[:Letter:]&[:Uppercase:]]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[[:...:]&[:...:]] セットの集合交差【INTERSECTION】

Page 139: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+\\.4D[\\p{Lu}]"$string:="sample.4DB"$match:=Match regex($regex;$string)

[\p{Lu}] プロパティで合致【Letter, Uppercase】

Page 140: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+[\\u0001]"$string:="abc"+char(1)$match:=Match regex($regex;$string)

[\\u0001] コードポイントに合致

Page 141: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:=".+[\\u0001-\\u0020]"$string:="abc"+char(9)$match:=Match regex($regex;$string)

[\\u0001-\\u0020] コードポイントの範囲に合致

Page 142: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:="[\\p{numeric_value=9}]+"$string:="ミヤコケイスケ"$match:=Match regex($regex;$string)

$regex:="[:Katakana:]+"$string:="abc"+char(9)$match:=Match regex($regex;$string)

[:Katakana:] プロパティで合致

Page 143: Regex

正規表現セット

http://userguide.icu-project.org/strings/regexp

$regex:="[\\p{numeric_value=9}]+"$string:="ミヤコケイスケ"$match:=Match regex($regex;$string)

$regex:="[:East Asian Width=Halfwidth:]+"$string:="abc"+char(9)$match:=Match regex($regex;$string)

[: property=value:] プロパティと値で合致

Page 144: Regex

正規表現

Page 145: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

Page 146: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

i 【英】大文字と小文字を区別しない

x パターン内のコメントを許可する

s 改行も文字として扱う("."に合致)

m 行単位で入力を処理する("^"に始まり"$"で終わる)

w ワードの区切りに境界解析を使用する("\b"に合致)

Page 147: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

i 【英】大文字と小文字を区別しない

x パターン内のコメントを許可する

s 改行も文字として扱う("."に合致)

m 行単位で入力を処理する("^"に始まり"$"で終わる)

w ワードの区切りに境界解析を使用する("\b"に合致)

Page 148: Regex

正規表現フラグ

i 【英】大文字と小文字を区別しない

定義: Uppercase, Lowercase, Titlecasehttp://unicode.org/faq/casemap_charprop.html

ラテン・ギリシャ・キリル・アルメニア文字・一部の古代文字

http://userguide.icu-project.org/strings/regexp

Page 149: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

i 【英】大文字と小文字を区別しない

$regex:="[^.]+\\.4db"$string:="sample.4DB"$match:=Match regex($regex;$string)

Page 150: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

i 【英】大文字と小文字を区別しない

$regex:="[^.]+\\.4db"$string:="sample.4DB"$match:=Match regex($regex;$string)

False

Page 151: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

i 【英】大文字と小文字を区別しない

$regex:="(?i)[^.]+\\.4db"$string:="sample.4DB"$match:=Match regex($regex;$string)

Page 152: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

i 【英】大文字と小文字を区別しない

$regex:="(?i)[^.]+\\.4db"$string:="sample.4DB"$match:=Match regex($regex;$string)

True

Page 153: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

s 改行も文字として扱う("."に合致)

C_LONGINT($pos;$len)$regex:="Content-Length:.+"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

Page 154: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

s 改行も文字として扱う("."に合致)

C_LONGINT($pos;$len)$regex:="Content-Length:.+"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

Content-Length:100

Page 155: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

s 改行も文字として扱う("."に合致)

C_LONGINT($pos;$len)$regex:="(?s)Content-Length:.+"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

Page 156: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

s 改行も文字として扱う("."に合致)

C_LONGINT($pos;$len)$regex:="(?s)Content-Length:.+"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1;$pos;$len)$substring:=Substring($string;$pos;$len)

Content-Length:100 Content-Type:application/json

Page 157: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

m 行単位で入力を処理する("^"に始まり"$"で終わる)

$regex:="^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

Page 158: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

m 行単位で入力を処理する("^"に始まり"$"で終わる)

$regex:="^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

False

Page 159: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

m 行単位で入力を処理する("^"に始まり"$"で終わる)

$regex:="(?m)^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

Page 160: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

m 行単位で入力を処理する("^"に始まり"$"で終わる)

$regex:="(?m)^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

True

Page 161: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="(?mi)^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

m 行単位で入力を処理する("^"に始まり"$"で終わる)

Page 162: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="(?mi)^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

True

m 行単位で入力を処理する("^"に始まり"$"で終わる)

Page 163: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="(?mi)^Content-Length:.+$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

True

m 行単位で入力を処理する("^"に始まり"$"で終わる)

(?mi) フラグの併用

Page 164: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="(?mi)^Content-Length:.+(?-m)$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

m 行単位で入力を処理する("^"に始まり"$"で終わる)

Page 165: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="(?mi)^Content-Length:.+(?-m)$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

m 行単位で入力を処理する("^"に始まり"$"で終わる)

(?-m) フラグの取り消し

Page 166: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="(?mi)^Content-Length:.+(?-m)$"$string:="Content-Length:100\r\n\ Content-Type:application/json"$match:=Match regex($regex;$string;1)

m 行単位で入力を処理する("^"に始まり"$"で終わる)

(?-m) フラグの取り消し

False

Page 167: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="[^.]+(?i:\\.4db)"$string:="sample.4DB"$match:=Match regex($regex;$string)

i 【英】大文字と小文字を区別しない

Page 168: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="[^.]+(?i:\\.4db)"$string:="sample.4DB"$match:=Match regex($regex;$string)

i 【英】大文字と小文字を区別しない

True

Page 169: Regex

正規表現フラグ

http://userguide.icu-project.org/strings/regexp

$regex:="[^.]+(?i:\\.4db)"$string:="sample.4DB"$match:=Match regex($regex;$string)

i 【英】大文字と小文字を区別しない

True

(?i:) カッコ内だけで有効なフラグ

Page 170: Regex

正規表現