正则表达式 BNF 语法

发布于 2024-07-07 17:16:13 字数 20 浏览 6 评论 0原文

正则表达式有BNF语法吗?

Is there any BNF grammar for regular expression?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

停滞 2024-07-14 17:16:13

您可以看到 Perl 正则表达式(显示 此处有更多详细信息,由 edg 发布)

You can see one for Perl regexp (displayed a little more in detail here, as posted by edg)

旧人哭 2024-07-14 17:16:13

要将它们发布到现场:

CMPT 384 讲义 Robert D. Cameron 11 月 29 日至 12 月 1 日,
1999年

BNF Grammar of Regular Expressions

Following the precedence rules given previously, a BNF grammar for Perl-style regular expressions can be constructed as follows.
<RE>    ::=     <union> | <simple-RE>
<union>     ::= <RE> "|" <simple-RE>
<simple-RE>     ::=     <concatenation> | <basic-RE>
<concatenation>     ::= <simple-RE> <basic-RE>
<basic-RE>  ::= <star> | <plus> | <elementary-RE>
<star>  ::= <elementary-RE> "*"
<plus>  ::= <elementary-RE> "+"
<elementary-RE>     ::= <group> | <any> | <eos> | <char> | <set>
<group>     ::=     "(" <RE> ")"
<any>   ::=     "."
<eos>   ::=     "$"
<char>  ::=     any non metacharacter | "\" metacharacter
<set>   ::=     <positive-set> | <negative-set>
<positive-set>  ::=     "[" <set-items> "]"
<negative-set>  ::=     "[^" <set-items> "]"
<set-items>     ::=     <set-item> | <set-item> <set-items>
<set-items>     ::=     <range> | <char>
<range>     ::=     <char> "-" <char>

通过 VonC

--- Knud van Eeden --- 2003 年 10 月 21 日 - 03:22 am --------------------

PERL:搜索/替换:正则表达式:巴科斯诺尔形式:什么是
正则表达式可能的 BNF 吗?

expression = term

             term | expression

term = factor

       factor term

factor = atom

         atom metacharacter

atom = character

       .

       ( expression )

       [ characterclass ]

       [ ^ characterclass ]

       { min }

       { min ,  }

       { min , max }

characterclass = characterrange

                 characterrange characterclass

characterrange = begincharacter

                 begincharacter - endcharacter

begincharacter = character

endcharacter = character

character =

            anycharacterexceptmetacharacters

            \ anycharacterexceptspecialcharacters

metacharacter = ?

                * {=0 or more, greedy}

                *? {=0 or more, non-greedy}

                + {=1 or more, greedy}

                +? {=1 or more, non-greedy}

                ^ {=begin of line character}

                $ {=end of line character}

                

要将它们发布到现场:

CMPT 384 讲义 Robert D. Cameron 11 月 29 日至 12 月 1 日,
1999年

BNF Grammar of Regular Expressions

Following the precedence rules given previously, a BNF grammar for Perl-style regular expressions can be constructed as follows.
<RE>    ::=     <union> | <simple-RE>
<union>     ::= <RE> "|" <simple-RE>
<simple-RE>     ::=     <concatenation> | <basic-RE>
<concatenation>     ::= <simple-RE> <basic-RE>
<basic-RE>  ::= <star> | <plus> | <elementary-RE>
<star>  ::= <elementary-RE> "*"
<plus>  ::= <elementary-RE> "+"
<elementary-RE>     ::= <group> | <any> | <eos> | <char> | <set>
<group>     ::=     "(" <RE> ")"
<any>   ::=     "."
<eos>   ::=     "$"
<char>  ::=     any non metacharacter | "\" metacharacter
<set>   ::=     <positive-set> | <negative-set>
<positive-set>  ::=     "[" <set-items> "]"
<negative-set>  ::=     "[^" <set-items> "]"
<set-items>     ::=     <set-item> | <set-item> <set-items>
<set-items>     ::=     <range> | <char>
<range>     ::=     <char> "-" <char>

通过 VonC

--- Knud van Eeden --- 2003 年 10 月 21 日 - 03:22 am --------------------

PERL:搜索/替换:正则表达式:巴科斯诺尔形式:什么是
正则表达式可能的 BNF 吗?

{=the characters to the left of the match}

通过艾德·吉尼斯

{=the characters to the right of the match}
amp; {=the characters that are matched}

                \t {=tab character}

                \n {=newline character}

                \r {=carriage return character}

                \f {=form feed character}

                \cX {=control character CTRL-X}

                \N {=the characters in Nth tag (if on match side)}

                $N{=the characters in Nth tag (if not on match side)}

                \NNN {=octal code for character NNN}

                \b {=match a 'word' boundary}

                \B {=match not a 'word' boundary}

                \d {=a digit, [0-9]}

                \D {=not a digit, [^0-9]}

                \s {=whitespace, [ \t\n\r\f]}

                \S {=not a whitespace, [^ \t\n\r\f]}

                \w {='word' character, [a-zA-Z0-9_]}

                \W {=not a 'word' character, [^a-zA-Z0-9_]}

                \Q {=put a quote (de-meta) on characters, until \E}

                \U {=change characters to uppercase, until \E}

                \L {=change characters to uppercase, until \E}

min = integer

max = integer

integer = digit

          digit integer

anycharacter = ! " # $ % & ' ( ) * + , - . / :
               ; < = > ? @ [ \ ] ^ _ ` { | } ~
               0 1 2 3 4 5 6 7 8 9
               A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
               a b c d e f g h i j k l m n o p q r s t u v w x y z

---

[book: see also: Bucknall, Julian - the Tomes of Delphi: Algorithms 
and Datastructures - p. 37 - 'Using regular expressions' - 
http://www.amazon.com/exec/obidos/tg/detail/-
/1556227361/qid=1065748783/sr=1-1/ref=sr_1_1/002-0122962-7851254?
v=glance&s=books]

---
---

Internet: see also:

---

Compiler: Grammar: Expression: Regular: Which grammar defines set of 
all regular expressions? [BNF]
http://www.faqts.com/knowledge_base/view.phtml/aid/25950/fid/1263

---

Perl Regular Expression: Quick Reference 1.05
http://www.erudil.com/preqr.pdf

---

Top: Computers: Programming: Languages: Regular Expressions: Perl
http://dmoz.org/Computers/Programming/Languages/Regular_Expressions/Per
l/

---

TSE: Search/Replace:Regular Expression:Backus Naur Form:What is 
possible BNF for regular expression?
http://www.faqts.com/knowledge_base/view.phtml/aid/25714/fid/1236

---

Delphi: Search: Regular expression: Create: How to create a regular 
expression parser in Delphi?
http://www.faqts.com/knowledge_base/view.phtml/aid/25645/fid/175

---

Delphi: Search: Regular expression: How to add regular expression 
searching to Delphi? [Systools]
http://www.faqts.com/knowledge_base/view.phtml/aid/25295/fid/175

----------------------------------------------------------------------

通过艾德·吉尼斯

To post them on-site:

CMPT 384 Lecture Notes Robert D. Cameron November 29 - December 1,
1999

BNF Grammar of Regular Expressions

Following the precedence rules given previously, a BNF grammar for Perl-style regular expressions can be constructed as follows.
<RE>    ::=     <union> | <simple-RE>
<union>     ::= <RE> "|" <simple-RE>
<simple-RE>     ::=     <concatenation> | <basic-RE>
<concatenation>     ::= <simple-RE> <basic-RE>
<basic-RE>  ::= <star> | <plus> | <elementary-RE>
<star>  ::= <elementary-RE> "*"
<plus>  ::= <elementary-RE> "+"
<elementary-RE>     ::= <group> | <any> | <eos> | <char> | <set>
<group>     ::=     "(" <RE> ")"
<any>   ::=     "."
<eos>   ::=     "$"
<char>  ::=     any non metacharacter | "\" metacharacter
<set>   ::=     <positive-set> | <negative-set>
<positive-set>  ::=     "[" <set-items> "]"
<negative-set>  ::=     "[^" <set-items> "]"
<set-items>     ::=     <set-item> | <set-item> <set-items>
<set-items>     ::=     <range> | <char>
<range>     ::=     <char> "-" <char>

via VonC.

--- Knud van Eeden --- 21 October 2003 - 03:22 am --------------------

PERL:Search/Replace:Regular Expression:Backus Naur Form:What is
possible BNF for regular expression?

expression = term

             term | expression

term = factor

       factor term

factor = atom

         atom metacharacter

atom = character

       .

       ( expression )

       [ characterclass ]

       [ ^ characterclass ]

       { min }

       { min ,  }

       { min , max }

characterclass = characterrange

                 characterrange characterclass

characterrange = begincharacter

                 begincharacter - endcharacter

begincharacter = character

endcharacter = character

character =

            anycharacterexceptmetacharacters

            \ anycharacterexceptspecialcharacters

metacharacter = ?

                * {=0 or more, greedy}

                *? {=0 or more, non-greedy}

                + {=1 or more, greedy}

                +? {=1 or more, non-greedy}

                ^ {=begin of line character}

                $ {=end of line character}

                

To post them on-site:

CMPT 384 Lecture Notes Robert D. Cameron November 29 - December 1,
1999

BNF Grammar of Regular Expressions

Following the precedence rules given previously, a BNF grammar for Perl-style regular expressions can be constructed as follows.
<RE>    ::=     <union> | <simple-RE>
<union>     ::= <RE> "|" <simple-RE>
<simple-RE>     ::=     <concatenation> | <basic-RE>
<concatenation>     ::= <simple-RE> <basic-RE>
<basic-RE>  ::= <star> | <plus> | <elementary-RE>
<star>  ::= <elementary-RE> "*"
<plus>  ::= <elementary-RE> "+"
<elementary-RE>     ::= <group> | <any> | <eos> | <char> | <set>
<group>     ::=     "(" <RE> ")"
<any>   ::=     "."
<eos>   ::=     "$"
<char>  ::=     any non metacharacter | "\" metacharacter
<set>   ::=     <positive-set> | <negative-set>
<positive-set>  ::=     "[" <set-items> "]"
<negative-set>  ::=     "[^" <set-items> "]"
<set-items>     ::=     <set-item> | <set-item> <set-items>
<set-items>     ::=     <range> | <char>
<range>     ::=     <char> "-" <char>

via VonC.

--- Knud van Eeden --- 21 October 2003 - 03:22 am --------------------

PERL:Search/Replace:Regular Expression:Backus Naur Form:What is
possible BNF for regular expression?

{=the characters to the left of the match}

via Ed Guinness.

{=the characters to the right of the match}
amp; {=the characters that are matched}

                \t {=tab character}

                \n {=newline character}

                \r {=carriage return character}

                \f {=form feed character}

                \cX {=control character CTRL-X}

                \N {=the characters in Nth tag (if on match side)}

                $N{=the characters in Nth tag (if not on match side)}

                \NNN {=octal code for character NNN}

                \b {=match a 'word' boundary}

                \B {=match not a 'word' boundary}

                \d {=a digit, [0-9]}

                \D {=not a digit, [^0-9]}

                \s {=whitespace, [ \t\n\r\f]}

                \S {=not a whitespace, [^ \t\n\r\f]}

                \w {='word' character, [a-zA-Z0-9_]}

                \W {=not a 'word' character, [^a-zA-Z0-9_]}

                \Q {=put a quote (de-meta) on characters, until \E}

                \U {=change characters to uppercase, until \E}

                \L {=change characters to uppercase, until \E}

min = integer

max = integer

integer = digit

          digit integer

anycharacter = ! " # $ % & ' ( ) * + , - . / :
               ; < = > ? @ [ \ ] ^ _ ` { | } ~
               0 1 2 3 4 5 6 7 8 9
               A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
               a b c d e f g h i j k l m n o p q r s t u v w x y z

---

[book: see also: Bucknall, Julian - the Tomes of Delphi: Algorithms 
and Datastructures - p. 37 - 'Using regular expressions' - 
http://www.amazon.com/exec/obidos/tg/detail/-
/1556227361/qid=1065748783/sr=1-1/ref=sr_1_1/002-0122962-7851254?
v=glance&s=books]

---
---

Internet: see also:

---

Compiler: Grammar: Expression: Regular: Which grammar defines set of 
all regular expressions? [BNF]
http://www.faqts.com/knowledge_base/view.phtml/aid/25950/fid/1263

---

Perl Regular Expression: Quick Reference 1.05
http://www.erudil.com/preqr.pdf

---

Top: Computers: Programming: Languages: Regular Expressions: Perl
http://dmoz.org/Computers/Programming/Languages/Regular_Expressions/Per
l/

---

TSE: Search/Replace:Regular Expression:Backus Naur Form:What is 
possible BNF for regular expression?
http://www.faqts.com/knowledge_base/view.phtml/aid/25714/fid/1236

---

Delphi: Search: Regular expression: Create: How to create a regular 
expression parser in Delphi?
http://www.faqts.com/knowledge_base/view.phtml/aid/25645/fid/175

---

Delphi: Search: Regular expression: How to add regular expression 
searching to Delphi? [Systools]
http://www.faqts.com/knowledge_base/view.phtml/aid/25295/fid/175

----------------------------------------------------------------------

via Ed Guinness.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文