正则表达式解释 smtlib2 格式

Regex to interpret smtlib2 format

我正在尝试找出一个可以匹配以 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-funInt()),然后读取数据,因为剩下的就是这样 1 28171 104

我只是想知道是否有更优雅的方法来做到这一点?

捕获这些子字符串:

\(define-fun\s+(\S+).*\n\s*(\d+)\)

参见regex proof

解释

--------------------------------------------------------------------------------
  \(                       '('
--------------------------------------------------------------------------------
  define-fun               'define-fun'
--------------------------------------------------------------------------------
  \s+                      whitespace (\n, \r, \t, \f, and " ") (1 or
                           more times (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  (                        group and capture to :
--------------------------------------------------------------------------------
    \S+                      non-whitespace (all but \n, \r, \t, \f,
                             and " ") (1 or more times (matching the
                             most amount possible))
--------------------------------------------------------------------------------
  )                        end of 
--------------------------------------------------------------------------------
  .*                       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 :
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
  )                        end of 
--------------------------------------------------------------------------------
  \)                       ')'