-
Notifications
You must be signed in to change notification settings - Fork 4
/
413.txt
273 lines (193 loc) · 12.5 KB
/
413.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
[39] [DFN[[RUBYB[[[正規表現]]]@en[regular expression]]]] ([DFN[[[正則表現]]]]) は、
[[正規言語]]を記述できる[[言語]]です。通常は[[文脈自由言語]]やそれ以上の[[言語]]を表現できるよう拡張されています。
[51] [[Unix]] の各種ツールや [[Perl]] などの[[プログラミング言語]]、
[[Emacs]] などの[[エディター]]など、非常に多くの[[ソフトウェア]]で採用されています。
ツールや言語によって様々な構文と意味のバリエーションがあり、
「[[正規表現]]」はそうした多数の[[言語]]の総称と言えます。
* 名称・略称
[23]
正規表現 = Regular expression でして、その略称としては
regex と regexp がともによく使われます。
[57] [[正規言語]] ([[正則言語]]) の表記法を指す時は、[[正則表現]]と呼ぶのが普通です。
[[正規表現]]と呼ぶ時のほとんどは、[[正則言語]]以上のものを表現できる拡張された表記法を指しています。
* 標準化
[8] [[正規表現]]には色々なバリエーションがあり、[[正規表現]]一般の[[標準]]は存在しない状態です。
互いに矛盾する機能もあり、完全な[[標準化]]は今後もあり得ないと思われます。
[61] 90年代後半から00年代にかけては、 [[Perl]] が[[正規表現]]の代表的な実装の1つであり、
活発に新機能を追加していました。 [[PCRE]] をはじめ他の色々な実装がこれに追随しており、
[[Perl]] が[[正規表現]]の[[事実上の標準]]の1つとみなされていました。
[60] 特定の適用範囲に限定した[[正規表現]]の[[仕様]]として[[標準化団体]]が制定したものには、
次のものがあります。
[FIG(middle list)[
- [[POSIX]]
- [[SUS]] (>>29)
- [[Unicode Regular Expressions]]
- [[ECMAScript]]
- [[C++]] (>>47)
- [[XML Schema 1.0]]
- [[XML Schema 1.1]]
- [[XQuery 1.0 and XPath 2.0 Functions and Operators]]
- [[ISO/IEC 30170]] / [[JIS X 3017]] ([[Ruby]])
- [[OpenPGP]] [SRC[>>62]]
]FIG]
[REFS[
- [29] [CITE[Regular Expressions]] ([TIME[2014-11-07 01:09:26 +09:00]] 版) <http://pubs.opengroup.org/onlinepubs/7908799/xbd/re.html>
- [47] [CITE[Working Draft, Standard for Programming
Language C++]] ([TIME[2012-01-16 08:04:26 +09:00]] 版) <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf#page=1107>
- [62] [CITE@en[RFC 4880 - OpenPGP Message Format]] ([TIME[2016-10-16 17:19:31 +09:00]] 版) <https://tools.ietf.org/html/rfc4880#section-8>
]REFS]
;; [48] [[XQuery 1.0 and XPath 2.0 Functions and Operators]] は [[XML Schema 1.0]]
の[[正規表現]]に多少の変更を加えています。
;; [49] [[C++]] は [[ECMAScript]] の[[正規表現]]に多少の変更を加えています [SRC[>>47]]。
;; [50] [[HTML]] は [[JavaScript]] ([[ECMAScript]]) を参照しており、
独自には定義していません。
* [24] 正規表現の多様性
[52] [[正規表現]]は、その実装によって様々な構文や意味となっています。
あまりにも多種多様なバリエーションが存在するため、おそらくどの[[正規表現]]のバリエーションでも共通して使えるのは、
[[ASCIIラテン文字]]と[[ASCII数字]]の[[連接]]くらいでしょう。
[25] [CITE@ja-JP[正規表現メモ]] ([[KIMURA koichi]] 著, [TIME[2008-01-18 01:53:04 +09:00]] 版) <http://www.kt.rim.or.jp/~kbk/regex/regex.html>
* [22] 可視化
[18] [CITE[ブラウザで正規表現のチェックなどができるサイトまとめ | IDEA*IDEA]] ([TIME[2008-12-06 12:08:45 +09:00]] 版) <http://www.ideaxidea.com/archives/2008/12/post_964.html>
[19] [CITE[Graph::Regexp - Create graphical flowchart from a regular expression - search.cpan.org]] ([TIME[2008-12-07 09:47:47 +09:00]] 版) <http://search.cpan.org/~tels/Graph-Regexp-0.05/lib/Graph/Regexp.pm>
[[Perl]] のデバッグ出力機能を使って可視化する。
[20] >>19 なんかこれ、単純なのでも間違って出てくるんだけど、大丈夫なんだろうか?
[21] [CITE@en[Regular expression visualizer]] ([TIME[2008-12-08 14:52:29 +09:00]] 版) <http://suika.fam.cx/regexp/visualizer/input>
* 歴史
- [1] ''正規表現道場@2ch Part2'' <http://pc2.2ch.net/test/read.cgi/php/1038146241/>
- [3] [WEAK[2003-11-22 07:11:25 +00:00]] ''[[名無しさん]]'': ''正規表現道場@2ch Part3 s/煽り|荒らし/あぼーん/g'' <http://pc2.2ch.net/test/read.cgi/php/1069245758/>
- [4] ''正規表現'' <http://pc.2ch.net/test/read.cgi/unix/1039165754/>
[11]
[CITE[正規表現 part 3]]
<http://pc8.2ch.net/test/read.cgi/tech/1156413899/>
[35]
>
Regular expressions provide a mechanism to select specific strings
from a set of character strings. Regular expressions are a
language used to search for text within strings, and possibly
modify the text found with other text. <NONE>
;; [CITE@en[RFC 3536 - Terminology Used in Internationalization in the IETF]] ([TIME[2011-01-29 02:14:52 +09:00]] 版) <http://tools.ietf.org/html/rfc3536#page-24>
[36] [[正則表現]]には言及無しwwwww
* メモ
[FIG(amazon)[
[[正規表現]]
]FIG]
- [2] [CODE(regexp)[(?:)]] ([[perl]], [[GNUEmacs]] 21+) == [CODE(regexp)[%()]] ([[Vim]])
- [5] ''contents of How to use (e|f)?grep'' <http://katsu.watanabe.name/grep/ohpcontents.html>
[6]
[CITE[Re: Character ranges in the XSD version XHTML 1.0 Strict]]
<mid:20050506.151451.108740468.mimasa@w3.org>
[[XML Schema]] の[[正規表現]]の文字範囲指定の規定の迷走
([[名無しさん]] [sage])
[7]
[CITE[Perl-compatible regular expression optimizer]] <http://bisqwit.iki.fi/source/regexopt.html>
([[名無しさん]] [WEAK[2006-01-23 00:03:50 +00:00]])
[9]
[CITE[最速インターフェース研究会 :: NamedCapture for JavaScript]] <http://la.ma.la/blog/diary_200603262310.htm>
([[名無しさん]] [WEAK[2006-03-27 23:52:31 +00:00]])
[10]
[CITE[XQuery 1.0 and XPath 2.0 Functions and Operators]] <http://www.w3.org/TR/xpath-functions/#regex-syntax>
[12]
[CITE@EN[XQuery 1.0 and XPath 2.0 Functions and Operators]] ([CODE[2007-01-19 07:02:42 +09:00]] 版) <http://www.w3.org/TR/2007/REC-xpath-functions-20070123/#regex-syntax>
([[名無しさん]])
[13]
[CITE[Bug 330352 – Very non-greedy regexp causes crash in jsregexp.c]] ([CODE[2007-02-13 23:10:53 +09:00]] 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=330352>
([[名無しさん]] [WEAK[2007-02-13 14:21:45 +00:00]])
[14]
[CITE[Bug 330352 – Very non-greedy regexp causes crash in jsregexp.c]] ([CODE[2007-02-13 23:10:53 +09:00]] 版) <https://bugzilla.mozilla.org/show_bug.cgi?id=330352>
([[名無しさん]] [WEAK[2007-02-13 14:26:25 +00:00]])
[15]
[CITE@en-us[SRX Specification]] ([CODE[2007-02-24 17:26:17 +09:00]] 版) <http://www.lisa.org/standards/srx/srx.html#Intro_RegExp>
([[名無しさん]])
[16]
[CITE@ja[Shibuya.js in Kyoto 発表資料「取説 正規表現」: Days on the Moon]] ([CODE[2008-07-26 22:51:06 +09:00]] 版) <http://nanto.asablo.jp/blog/2008/07/21/3640937>
([[名無しさん]])
[17]
[CITE[ECMAScript デス 3]]
<http://pc11.2ch.net/test/read.cgi/tech/1190160481/432>
>
'aaaggfeeeehhh'.split(/(?=(.)\1*)/);
>
-IE6: a,a,a,g,g,f,e,e,e,e,h,h,h
-Firefox3: a,a,a,a,a,g,g,g,g,f,f,e,e,e,e,e,e,e,e,h,h,h,h,h,h,h
-Chrome: a,a,a,a,a,g,g,g,g,f,f,e,e,e,e,e,e,e,e,h,h,h,h,h,h
[26] [CITE@ja[Lesson1 Step2 検索条件を設定しよう ~簡易表現と正規表現~ - 超漢字ウェブサイト]] ([TIME[2008-07-09 11:32:56 +09:00]] 版) <http://www.chokanji.com/knowhow/vol01_02.html>
[27] >>26 で特徴的なのは:
>
,&TNNNNNN; ,1文字を[[テキスト形式TRONコード]]で表記します。
>
,[:名前:] ,あらかじめ名前の決まっている文字クラスを指定します。日本基本、日本補助、GT、大漢和、中国、韓国、台湾、各国、JIS第1第2、JIS第3、JIS第4が使用できます。(検索文字列) '''['''[:中国:]''']'''
[28] [[RFC 5444]] は [[SUS]] を参照しつつ[[正規表現]]風味の [[BNF]]
を独自に定義し、それを用いて書式を定義しています。
[30] [CITE[正規表現の文字クラスまとめ - 名もないテクノ手]] ([TIME[2009-03-09 22:39:19 +09:00]] 版) <http://d.hatena.ne.jp/seuzo/20090309/1236525090>
[31] >>30 は [[InDesign]]。ほぼ [[Perl]] と同じかな。 [CODE(regexp)[[['''[''':unicode:''']''']]]]
なんてのがあるんだ。
[32] [CITE[正規表現で素数判定 - NO!と言えるようになりたい]]
([TIME[2010-07-24 13:51:10 +09:00]] 版)
<http://d.hatena.ne.jp/ytakano/20100721/1279736214>
[33] [CITE@EN[XQuery 1.0 and XPath 2.0 Functions and Operators (Second Edition)]]
( ([TIME[2010-12-17 00:06:54 +09:00]] 版))
<http://www.w3.org/TR/2010/REC-xpath-functions-20101214/#regex-syntax>
[34] [CITE@en-US[Efficient XML Interchange (EXI) Format 1.0]]
( ([TIME[2011-03-10 23:00:15 +09:00]] 版))
<http://www.w3.org/TR/2011/REC-exi-20110310/#regexToCharset>
[37] [CITE@EN[W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes]]
( ([TIME[2012-04-05 06:34:51 +09:00]] 版))
<http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#regexs>
[38] [CITE@EN[SPARQL 1.1 Query Language]]
( ([TIME[2013-03-21 20:27:53 +09:00]] 版))
<http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-regex>
[40] [CITE@EN[XPath and XQuery Functions and Operators 3.0]]
( ([TIME[2014-04-08 07:02:07 +09:00]] 版))
<http://www.w3.org/TR/xpath-functions-3/#regex-syntax>
[41] [CITE@en-US[Internationalization Tag Set (ITS) Version 2.0]]
( ([TIME[2013-10-27 19:39:43 +09:00]] 版))
<http://www.w3.org/TR/its20/#allowedchars>
[42] [CITE@ja[Emacs Lisp]]
( ([TIME[2014-06-17 06:23:25 +09:00]] 版))
<http://www.mew.org/~kazu/doc/elisp/regexp.html>
[43] [CITE@ja[K.Takata's software: bregonig.dll]]
( ([TIME[2014-09-18 21:57:55 +09:00]] 版))
<http://homepage3.nifty.com/k-takata/mysoft/bregonig.html>
[44] [CITE@en[k-takata/Onigmo]]
( ([TIME[2014-11-07 00:58:41 +09:00]] 版))
<https://github.com/k-takata/Onigmo>
[45] [CITE[Oniguruma]]
( ([TIME[2014-11-07 00:58:38 +09:00]] 版))
<http://www.geocities.jp/kosako3/oniguruma/>
[46] [CITE[Pattern (Java Platform SE 6)]]
( ([TIME[2011-12-02 14:55:51 +09:00]] 版))
<http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html>
[FIG(quote)[
[FIGCAPTION[
[53] [CITE[OASIS Open Document Format for Office Applications (OpenDocument) Version 1.2 - Part 1: OpenDocument Schema]]
([TIME[2011-09-29 13:00:00 +09:00]] 版)
<http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#a19_743table_use-regular-expressions>
]FIGCAPTION]
> Regular expressions are implementation-dependent expressions that, at a minimum, conform to the requirements of Conformance Clause C1 of '''['''UTR18''']'''.
]FIG]
[54] [CITE@en[regex - Rust]]
( ([TIME[2015-02-04 22:01:13 +09:00]] 版))
<http://doc.rust-lang.org/regex/regex/index.html>
[55] [CITE@en[RFC 2440 - OpenPGP Message Format]]
([TIME[2015-02-15 14:39:41 +09:00]] 版)
<https://tools.ietf.org/html/rfc2440#section-8>
[56] [CITE@en[RFC 4880 - OpenPGP Message Format]]
([TIME[2015-04-05 14:41:03 +09:00]] 版)
<https://tools.ietf.org/html/rfc4880#section-8>
[FIG(quote)[
[FIGCAPTION[
[58] [CITE@en[Model for Tabular Data and Metadata on the Web]]
([TIME[2015-12-03 19:28:42 +09:00]] 版)
<http://www.w3.org/TR/2015/REC-tabular-data-model-20151217/#h-formats-for-durations>
]FIGCAPTION]
> If the datatype base is a duration type, the datatype format annotation provides a regular expression for the string values, with syntax and processing defined by '''['''ECMASCRIPT''']'''. If the supplied value is not a valid regular expression, implementations must issue a warning and proceed as if no format had been provided.
]FIG]
[FIG(quote)[
[FIGCAPTION[
[59] [CITE@en[Model for Tabular Data and Metadata on the Web]]
([TIME[2015-12-03 19:28:42 +09:00]] 版)
<http://www.w3.org/TR/2015/REC-tabular-data-model-20151217/#h-formats-for-other-types>
]FIGCAPTION]
> If the datatype base is not numeric, boolean, a date/time type, or a duration type, the datatype format annotation provides a regular expression for the string values, with syntax and processing defined by '''['''ECMASCRIPT''']'''. If the supplied value is not a valid regular expression, implementations must issue a warning and proceed as if no format had been provided.
]FIG]
[63] [[POSIX]] の[[正規表現]]は[[字句模型記法]]としても使うことができます。