Search code examples
pythonregexz3

How do I concatenate two regexes with the Python Z3 bindings?


I see from this question that there's a re.++ function in the SMTLIB bindings that seems to do what I want. What is its equivalent in the Python bindings? For example:

from z3 import *
r1 = Star(Re('ab'))
r2 = Re('a')
r_concatenated = Re(r1 ++ r2)

which would be equivalent to the regex ab*a. How do I get r_concatenated?


Solution

  • I found the answer about one minute after posting this question. If you use the Concat method it works, although the documentation only mentions bitvectors. So the code would be:

    from z3 import *
    r1 = Star(Re('ab'))
    r2 = Re('a')
    r_concatenated = Concat(r1, r2)