Skip to content

Commit

Permalink
Add description for absent operator (Issue #82)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-takata committed Dec 22, 2016
1 parent df237ff commit e621f69
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
25 changes: 24 additions & 1 deletion doc/RE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Onigmo (Oniguruma-mod) Regular Expressions Version 6.0.0 2016/12/01
Onigmo (Oniguruma-mod) Regular Expressions Version 6.1.0 2016/12/22

syntax: ONIG_SYNTAX_RUBY (default)

Expand Down Expand Up @@ -308,6 +308,29 @@ syntax: ONIG_SYNTAX_RUBY (default)
left-most group is checked, but it should be the
same as \k<name>.

(?~subexp) absent operator (experimental)
Matches any string which ending doesn't match subexp.

E.g.:
(?~abc) matches: "", "ab", "aab", "cccc", etc.
It doesn't match: "abc", "aabc", "ccccabc", etc.

\/\*(?~\*\/)\*\/ matches C style comments:
"/**/", "/* foobar */", etc.

\A\/\*(?~\*\/)\*\/\z doesn't match "/**/ */".
This is different from \A\/\*.*?\*\/\z .

(?~) matches nothing.

Theoretical backgrounds are discussed in Tanaka Akira's
paper and slide (both Japanese):

* Absent Operator for Regular Expression
https://staff.aist.go.jp/tanaka-akira/pub/prosym49-akr-paper.pdf
* 正規表現における非包含オペレータの提案
https://staff.aist.go.jp/tanaka-akira/pub/prosym49-akr-presen.pdf


8. Backreferences

Expand Down
25 changes: 24 additions & 1 deletion doc/RE.ja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
鬼雲 (鬼車改) 正規表現 Version 6.0.0 2016/12/01
鬼雲 (鬼車改) 正規表現 Version 6.1.0 2016/12/22

使用文法: ONIG_SYNTAX_RUBY (既定値)

Expand Down Expand Up @@ -306,6 +306,29 @@
最も左のグループを参照するが、これは本来 \k<name>
と同じ動作になるべきである。

(?~式) 非包含オペレータ (実験的)
終端が式にマッチしない任意の文字列にマッチする。

例:
(?~abc) は以下にマッチする: "", "ab", "aab", "cccc" 等
以下にはマッチしない: "abc", "aabc", "ccccabc" 等

\/\*(?~\*\/)\*\/ は C スタイルのコメントにマッチする:
"/**/", "/* foobar */" 等

\A\/\*(?~\*\/)\*\/\z は "/**/ */" にはマッチしない。
これは \A\/\*.*?\*\/\z とは異なる。

(?~) は何にもマッチしない。

理論的背景は田中哲氏の論文とスライドで議論されている
(どちらも日本語):

* Absent Operator for Regular Expression
https://staff.aist.go.jp/tanaka-akira/pub/prosym49-akr-paper.pdf
* 正規表現における非包含オペレータの提案
https://staff.aist.go.jp/tanaka-akira/pub/prosym49-akr-presen.pdf


8. 後方参照

Expand Down

0 comments on commit e621f69

Please sign in to comment.