Mastering Regular Expressions with Softanza: A Modern Approach to Pattern Matching
At the heart of Softanza's regex implementation is a more intuitive approach to pattern matching. Let's compare the traditional low-level approach with Softanza's semantic style:
by Mansour Ayouni · in the repository since 2025-02-04 · tutorial · area Pattern matching
Regular expressions are a powerful tool for pattern matching and text processing, but their traditional syntax and behavior can be complex and unintuitive. Softanza's stzRegex class reimagines regex programming with a more semantic, scope-oriented approach while leveraging the robust Softanza Engine's regular expression capabilities underneath. Let's explore how Softanza makes regex programming more accessible and maintainable.
Core Concepts and Basic Pattern Matching
# Low-level style pattern matching (originally Qt-based)
oQRegex = new QRegularExpression("pattern")
oMatch = oQRegex.match(cStr, 0, 0)
bMatched = oMatch.hasMatch()
# Softanza's semantic approach
oRegex = new stzRegex("pattern")
bMatched = oRegex.Match(cStr)illustration
Softanza eliminates the need to understand low-level details like match types and offset positions for basic pattern matching. The Match() function provides a clear, straightforward way to check if a pattern matches a string.
Scope-Oriented Pattern Matching
One of Softanza's major innovations is its scope-oriented approach to pattern matching. Instead of requiring developers to manage regex metacharacters manually, it provides semantic functions that handle common matching scenarios:
oRegex = new stzRegex("pattern")
# Match within specific scopes
bMatchedLine = oRegex.MatchLine(cStr) # Line-based matching
bMatchedWord = oRegex.MatchWord(cStr) # Word boundary matching
bMatchedSegment = oRegex.MatchSegment(cStr) # Segment-based matchingillustration
These scope-based functions automatically handle: - Line boundaries with appropriate multiline flags - Word boundaries with \b markers - Segment handling with proper dot behavior - Greedy vs non-greedy matching
This approach makes it much easier to express intent and avoid common regex pitfalls.
Real-Time Pattern Matching
Softanza introduces innovative solutions for real-time pattern matching scenarios, particularly useful in user interfaces:
oRegex = new stzRegex("^\d{3}-\d{2}-\d{4}$") # Social Security Number pattern
# Real-time validation as user types
bValid = oRegex.MatchAsYouType(cUserInput)
# Progressive search matching
bPotentialMatch = oRegex.MatchInProgress(cSearchText)illustration
The MatchAsYouType() function is specifically designed for form validation, returning true for both complete matches and partial matches that could become valid. This is a significant improvement over a more complex low-level partial match handling:
# Low-level approach to partial matching (originally Qt-based) oQRegex = new QRegularExpression(pattern) oMatch = oQRegex.match(text, 0, QRegularExpression.PartialPreferComplete) bValid = oMatch.hasMatch() or oMatch.hasPartialMatch() # Softanza's intuitive approach bValid = oRegex.MatchAsYouType(text)
illustration
Capturing and Extracting Information
Softanza simplifies the capture group handling process with clear semantic methods:
oRegex = new stzRegex("(\w+):(\d+)")
oRegex.Match("name:123")
# Get captured values
aValues = oRegex.Capture() # Returns ["name", "123"]
# Get captured values with positions
aValuesWithPos = oRegex.CaptureZ() # Returns with positions
aFullInfo = oRegex.CaptureZZ() # Returns with start/end positionsillustration
The Z-suffix convention in method names consistently indicates when position information is included in the return value, making it easy to choose the right method for your needs.
Recursive (Nested) Pattern Matching
Softanza provides enhanced support for handling nested patterns, common in parsing structured text:
# Match nested parentheses
oRegex = new stzRegex("\((?:[^()]+|(?R))*\)")
oRegex.MatchRecursive("(a(b)c)")
# Get information about nested matches
aInfo = oRegex.RecursiveMatchInfo()
nDepth = oRegex.RecursiveDepth()
aMatches = oRegex.RecursiveSubStrings()illustration
The recursive matching capabilities are wrapped in semantic methods that make it easier to understand and work with nested structures.
Pattern Analysis and Explanation
Softanza includes built-in support for understanding regex patterns:
oRegex = new stzRegex("\b\w+@\w+\.\w+\b")
cExplanation = oRegex.Explain()
cDetailedExplanation = oRegex.ExplainXT()illustration
This self-documentation feature helps developers understand complex patterns and aids in maintenance.
Conclusion
Softanza's stzRegex class represents a fundamental reimagining of how developers interact with regular expressions. By providing semantic, scope-oriented methods and handling common use cases elegantly, it makes regex programming more accessible and maintainable. The combination of the Softanza Engine's powerful regex capabilities with Softanza's intuitive interface creates a robust foundation for pattern matching in modern applications.
Cite
Mansour Ayouni. "Mastering Regular Expressions with Softanza: A Modern Approach to Pattern Matching". Softanza narrations, 2025. https://mayouni.github.io/stzsite/en/narrations/stzregex-mastering-regex-with-softanza-narration.html
Run in Haro's name on 2026-10-08 20:44 inside the library at commit 4a184e6f0, block after block in one process: 0 of 7 blocks kept their promise; the others are illustrations. The code of the articles is Haro code. Where an article was written before the language took its present name, the name was changed and nothing else. Genre, area and series read from the file's name, the year from its first commit: derived, until the article carries its own header. The file on GitHub(opens in a new tab)

