Skip to main content
Z3 provides comprehensive support for reasoning about strings and sequences through the string/sequence theory. This enables solving constraints involving string operations, pattern matching with regular expressions, and sequence manipulation.

Overview

Z3’s sequence and string support includes:
  • String operations: Concatenation, length, substring, indexing, replacement
  • Regular expressions: Pattern matching, intersection, union, complement
  • Sequence operations: Generic sequences over any sort
  • String constraints: Membership, prefix/suffix, contains
  • Conversions: String to/from integers

String Basics

Creating Strings

Basic String Operations

String Constraints

Contains, Prefix, and Suffix

Index and Replacement

String Conversion

Regular Expressions

Z3 supports rich regular expression constraints:

Basic Regular Expressions

Complex Regular Expression Patterns

Regular Expression Operations

Sequences

Sequences generalize strings to work over any element sort:

Sequence Operations

Sequence Constraints

Advanced String Features

Higher-Order Sequence Functions

Z3 4.15.5+ includes sequence map and fold operations:

Character Operations

Practical Examples

Password Validation

URL Parsing

String Puzzle Solving

C API Reference

String and sequence operations in C:

Key Functions

See Also