簡體   English   中英

分割BNF語法符號的正則表達式

[英]A regular expression for splitting symbols of a BNF grammar

我需要遍歷形式生產規則的符號:

例如:輸入

<relational operator> ::= = | <> | < | <= | >= | > | in
<next constant definition> ::= <empty> | <next constant definition> ; <constant definition>

所以我需要派一個正則表達式來分割文本。 這是我到目前為止的

(?:\s|^|\s<|^<)(?:.*?)(?:\s|$|\s>|>$)

問題是re.findall()沒有產生我想要的輸出

預期輸出為:

[<relational operator>, ::=, =, |, <>, |, <, |, <=, |, >=, |, >, |, in]
[<next constant definition>, ::=, <empty>, |, <next constant definition>, ;, <constant definition>]

如何使用類似<\\w+(?:\\s+\\w+)*>|\\S+

   < \w+ 
   (?: \s+ \w+ )*
   >
|  
   \S+ 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM