regex - 正则表达式解释 smtlib2 格式
问题描述
我试图找出一个正则表达式,它可以匹配以 smtlib 格式输出的程序的结果。基本上,我的数据采用以下形式:
(define-fun X_1 () Int
281)
(define-fun X_71 () Int
104)
(define-fun X_90 () Int
21)
(define-fun X_54 () Int
250)
etc.
是否可以编写匹配的表达式:
X_1 (...) 281
X_71 (...) 104
X_90 (...) 21
etc.
我目前的方法是使用 查找单个事件\(define-fun[\w\s]+\)
,然后对于每个事件,删除(define-fun
、、和Int
,然后读取数据,因为剩下的就是
,()
)
1 281
71 104
我只是想知道是否有更优雅的方式来做到这一点?
解决方案
捕获这些子字符串:
\(define-fun\s+(\S+).*\n\s*(\d+)\)
请参阅正则表达式证明。
解释
--------------------------------------------------------------------------------
\( '('
--------------------------------------------------------------------------------
define-fun 'define-fun'
--------------------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
\S+ non-whitespace (all but \n, \r, \t, \f,
and " ") (1 or more times (matching the
most amount possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
--------------------------------------------------------------------------------
\n '\n' (newline)
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
) end of \2
--------------------------------------------------------------------------------
\) ')'
推荐阅读
- c# - 使用从 mysql 到 raport/pdf/word C# 的数据创建表的问题
- excel - 如何删除具有零的特定多个列?
- spring-boot - Spring数据JPA中按时间戳排序
- javascript - 如何从 node.js 连接到 sql DB?
- laravel - Laravel 数据映射
- android - 带有 countryISO 的 PhoneNumberFormattingTextWatcher 在 api 级别 21 以下不可用
- elasticsearch - 使用 Nest 7.x 重新创建 ElasticSearch 索引
- vb.net - 如何在不重置其列属性的情况下对数据表进行排序?
- php - 没有作曲家的谷歌登录页面PHP
- html - CSS 照片库 wGrid - 间隙问题 // 图像周围的边距