1

我试图找出一个正则表达式,它可以匹配以 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 28171 104

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

4

1 回答 1

1

捕获这些子字符串:

\(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
--------------------------------------------------------------------------------
  \)                       ')'
于 2021-06-06T20:07:56.683 回答