regular expression

regular expression

[39] 正規表現 (regular expression) (正則表現) は、 正規言語を記述できる言語です。 ただし、通常用いられるものは文脈自由言語やそれ以上の言語を表現できるよう拡張されています。

[51] Unix の各種ツールや Perl などのプログラミング言語Emacs などのエディターなど、非常に多くのソフトウェアで採用されています。 ツールや言語によって様々な構文と意味のバリエーションがあり、 「正規表現」はそうした多数の言語の総称と言えます。

名称・略称

[23] 正規表現 = Regular expression でして、その略称としては regex と regexp がともによく使われます。

[57] 正規言語 (正則言語) の表記法を指す時は、正則表現と呼ぶのが普通です。 正規表現と呼ぶ時のほとんどは、正則言語以上のものを表現できる拡張された表記法を指しています。

標準化

[8] 正規表現には色々なバリエーションがあり、正規表現一般の標準は存在しない状態です。 互いに矛盾する機能もあり、完全な標準化は今後もあり得ないと思われます。

[61] 90年代後半から00年代にかけては、 Perl正規表現の代表的な実装の1つであり、 活発に新機能を追加していました。 PCRE をはじめ他の色々な実装がこれに追随しており、 Perl正規表現事実上の標準の1つとみなされていました。 ただし完全な可搬性が実現されていたわけではなく、 任意の Perlコードを埋め込めるような機能のように Perl 以外では実装不能な部分すらあります。

[60] 正規表現仕様として標準化団体等が制定したものには、 次のものがあります。

[48] XQuery 1.0 and XPath 2.0 Functions and OperatorsXML Schema 1.0正規表現に多少の変更を加えています。
[49] C++ECMAScript正規表現に多少の変更を加えています >>47
[50] HTMLJavaScript (ECMAScript) を参照しており、 独自には定義していません。

[71] UTS #37 は、 Perl 5.8 正規表現を参照しています。

[80] Table Schema | Frictionless Standards, , https://specs.frictionlessdata.io/table-schema/#constraints

XML Schema 正規表現を採用。

[24] 正規表現の多様性

[52] 正規表現は、その実装によって様々な構文や意味となっています。 あまりにも多種多様なバリエーションが存在するため、おそらくどの正規表現のバリエーションでも共通して使えるのは、 ASCIIラテン文字ASCII数字連接くらいでしょう。

[25] 正規表現メモ (KIMURA koichi 著, 版) http://www.kt.rim.or.jp/~kbk/regex/regex.html

構文

[73] 正規表現の構文

文脈

[74] BSON (Binary JSON): Specification, , https://bsonspec.org/spec.html

[75] BSON正規表現のデータ型を定めています。

[76] >>74 には

Regular expression - The first cstring is the regex pattern, the second is the regex options string. Options are identified by characters, which must be stored in alphabetical order. Valid options are 'i' for case insensitive matching, 'm' for multiline matching, 'x' for verbose mode, 'l' to make \w, \W, etc. locale dependent, 's' for dotall mode ('.' matches everything), and 'u' to make \w, \W, etc. match unicode.

とあり、2つの文字列の組で表されることと、その意味の一部が例示により示されていますが、 定義はこれですべてです。

[77] 相互運用性はハナから想定してない感じ?

[78] MongoDB Extended JSON はもう少し細かく定めていますが、やはり不明瞭。 しかし JavaScript正規表現を想定してるっぽいことが書いてあります。

[22] 可視化

[18] ブラウザで正規表現のチェックなどができるサイトまとめ | IDEA*IDEA ( 版) http://www.ideaxidea.com/archives/2008/12/post_964.html

[19] Graph::Regexp - Create graphical flowchart from a regular expression - search.cpan.org ( 版) http://search.cpan.org/~tels/Graph-Regexp-0.05/lib/Graph/Regexp.pm

Perl のデバッグ出力機能を使って可視化する。

[20] >>19 なんかこれ、単純なのでも間違って出てくるんだけど、大丈夫なんだろうか?

[21] Regular expression visualizer ( 版) https://suika.suikawiki.org/regexp/visualizer/input

歴史

[11] 正規表現 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>

[36] 正則表現には言及無しwwwww

メモ

正規表現

[6] Re: Character ranges in the XSD version XHTML 1.0 Strict mid:20050506.151451.108740468.mimasa@w3.org

XML Schema正規表現の文字範囲指定の規定の迷走 (名無しさん [sage])

[7] Perl-compatible regular expression optimizer http://bisqwit.iki.fi/source/regexopt.html (名無しさん 2006-01-23 00:03:50 +00:00)

[9] 最速インターフェース研究会 :: NamedCapture for JavaScript http://la.ma.la/blog/diary_200603262310.htm (名無しさん 2006-03-27 23:52:31 +00:00)

[10] XQuery 1.0 and XPath 2.0 Functions and Operators http://www.w3.org/TR/xpath-functions/#regex-syntax

[12] XQuery 1.0 and XPath 2.0 Functions and Operators (2007-01-19 07:02:42 +09:00 版) http://www.w3.org/TR/2007/REC-xpath-functions-20070123/#regex-syntax (名無しさん)

[13] Bug 330352 &#8211; Very non-greedy regexp causes crash in jsregexp.c (2007-02-13 23:10:53 +09:00 版) https://bugzilla.mozilla.org/show_bug.cgi?id=330352 (名無しさん 2007-02-13 14:21:45 +00:00)

[14] Bug 330352 &#8211; Very non-greedy regexp causes crash in jsregexp.c (2007-02-13 23:10:53 +09:00 版) https://bugzilla.mozilla.org/show_bug.cgi?id=330352 (名無しさん 2007-02-13 14:26:25 +00:00)

[15] SRX Specification (2007-02-24 17:26:17 +09:00 版) http://www.lisa.org/standards/srx/srx.html#Intro_RegExp (名無しさん)

[16] Shibuya.js in Kyoto 発表資料「取説 正規表現」: Days on the Moon (2008-07-26 22:51:06 +09:00 版) http://nanto.asablo.jp/blog/2008/07/21/3640937 (名無しさん)

[17] 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] Lesson1 Step2 検索条件を設定しよう ~簡易表現と正規表現~ - 超漢字ウェブサイト ( 版) http://www.chokanji.com/knowhow/vol01_02.html

[27] >>26 で特徴的なのは:

&TNNNNNN;1文字をテキスト形式TRONコードで表記します。
[:名前:]あらかじめ名前の決まっている文字クラスを指定します。日本基本、日本補助、GT、大漢和、中国、韓国、台湾、各国、JIS第1第2、JIS第3、JIS第4が使用できます。(検索文字列) [[:中国:]]

[28] RFC 5444SUS を参照しつつ正規表現風味の BNF を独自に定義し、それを用いて書式を定義しています。

[30] 正規表現の文字クラスまとめ - 名もないテクノ手 ( 版) http://d.hatena.ne.jp/seuzo/20090309/1236525090

[31] >>30InDesign。ほぼ Perl と同じかな。 [:unicode:] なんてのがあるんだ。

[32] 正規表現で素数判定 - NO!と言えるようになりたい ( 版) http://d.hatena.ne.jp/ytakano/20100721/1279736214

[33] XQuery 1.0 and XPath 2.0 Functions and Operators (Second Edition) ( ( 版)) http://www.w3.org/TR/2010/REC-xpath-functions-20101214/#regex-syntax

[34] Efficient XML Interchange (EXI) Format 1.0 ( ( 版)) http://www.w3.org/TR/2011/REC-exi-20110310/#regexToCharset

[37] W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes ( ( 版)) http://www.w3.org/TR/2012/REC-xmlschema11-2-20120405/#regexs

[38] SPARQL 1.1 Query Language ( ( 版)) http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#func-regex

[40] XPath and XQuery Functions and Operators 3.0 ( ( 版)) http://www.w3.org/TR/xpath-functions-3/#regex-syntax

[41] Internationalization Tag Set (ITS) Version 2.0 ( ( 版)) http://www.w3.org/TR/its20/#allowedchars

[42] Emacs Lisp ( ( 版)) http://www.mew.org/~kazu/doc/elisp/regexp.html

[43] K.Takata's software: bregonig.dll ( ( 版)) http://homepage3.nifty.com/k-takata/mysoft/bregonig.html

[44] k-takata/Onigmo ( ( 版)) https://github.com/k-takata/Onigmo

[45] Oniguruma ( ( 版)) http://www.geocities.jp/kosako3/oniguruma/

[46] Pattern (Java Platform SE 6) ( ( 版)) http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

[53] OASIS Open Document Format for Office Applications (OpenDocument) Version 1.2 - Part 1: OpenDocument Schema ( 版) http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#a19_743table_use-regular-expressions

Regular expressions are implementation-dependent expressions that, at a minimum, conform to the requirements of Conformance Clause C1 of [UTR18].

[54] regex - Rust ( ( 版)) http://doc.rust-lang.org/regex/regex/index.html

[55] RFC 2440 - OpenPGP Message Format ( 版) https://tools.ietf.org/html/rfc2440#section-8

[56] RFC 4880 - OpenPGP Message Format ( 版) https://tools.ietf.org/html/rfc4880#section-8

[58] Model for Tabular Data and Metadata on the Web ( 版) http://www.w3.org/TR/2015/REC-tabular-data-model-20151217/#h-formats-for-durations

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.

[59] Model for Tabular Data and Metadata on the Web ( 版) http://www.w3.org/TR/2015/REC-tabular-data-model-20151217/#h-formats-for-other-types

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.

[63] POSIX正規表現字句模型記法としても使うことができます。

[64] XPath and XQuery Functions and Operators 3.1 () https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#string.match

[65] RFC 2168 - Resolution of Uniform Resource Identifiers using the Domain Name System () https://tools.ietf.org/html/rfc2168#page-13

[66] RFC 2915 - The Naming Authority Pointer (NAPTR) DNS Resource Record () https://tools.ietf.org/html/rfc2915#section-3

[67] 544123 - Google Chrome Helper consumes 100% of CPU with the following regular expression - chromium - Monorail ( ()) https://bugs.chromium.org/p/chromium/issues/detail?id=544123

[68] XSL Transformations (XSLT) Version 3.0 () https://www.w3.org/TR/2017/REC-xslt-30-20170608/#regular-expressions

[69] Concise Binary Object Representation (CBOR) () https://cbor-wg.github.io/CBORbis/#encodedtext

Tag 35 is for regular expressions in Perl Compatible Regular Expressions (PCRE) / JavaScript syntax [ECMA262].

[70] Syntax · google/re2 Wiki () https://github.com/google/re2/wiki/Syntax

[72] 大名 力 (Tsutomu Ohna) - マイポータル - researchmap, Japan Science and Technology Agency, https://researchmap.jp/multidatabases/multidatabase_contents/detail/286001/380b009ff5d2d26cfb2321ae7b8b9d2f

[79] wakaba/perl-regexp-utils: Perl modules for regular expressions, https://github.com/wakaba/perl-regexp-utils