0

I have a problem using Z3 Java-API to compare the String with the regular expression.

For some target regular expressions:

"^[a-zA-Z]"

When I try to match the Strings with the regular expressions, it is still recognized as a string. For example:

SeqExpr c1 = ctx.mkString("^[a-zA-Z]");
ReExpr c2 = ctx.mkToRe(ctx.mkString("abc"));

s.add(ctx.mkInRe(c1, c2));
s.check();

System.out.println("c1 = " + c1);
System.out.println("mkInRe = " + ctx.mkInRe(c1, c2));
System.out.println(s.check());

The result is:

c1 = "^[a-zA-Z]"
mkInRe = (str.in.re "^[a-zA-Z]" (str.to.re "abc"))
UNSATISFIABLE

The "^[a-zA-Z]" whole part is recognized as a string but not a regular expression.

And I found that Defining constraints in Z3 using Boolean operators, this question would be highly related, Can something similar about the regular expression be done in Z3 Java?

Thanks!

4
  • Just like in the Python answer you linked, there's no function to convert a string to a regular-expression object in Java either. You'll have to construct your regular-expression piecemeal using the simpler functions in the API. See: github.com/Z3Prover/z3/blob/… Commented Apr 20, 2019 at 2:10
  • This would require a new compiler from Java (or Python) strings to Z3-regexp, which can definitely be done, but so far I think nobody has done it. Z3 gladly accepts contributions though! Commented Apr 20, 2019 at 17:21
  • @LeventErkok Thanks for your reply! But I still kind of confused, I tried to use these function but the function does not implement. Would you please be more specific? For example, I want to check whether in the string "I love Z3" have "love" in it, what should I do? Thanks a lot! Commented Apr 20, 2019 at 21:28
  • @ChristophWintersteiger Thanks for your reply! I will try my best to do it! Commented Apr 20, 2019 at 21:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.