simple_regex

High-Level Regular Expressions for Eiffel

v1.0.0 MIT

Overview

simple_regex provides a clean, high-level API for regular expressions in Eiffel. It wraps Gobo's PCRE engine while providing modern conveniences like a fluent builder, pre-built validation patterns, and Design by Contract support.

Features

SIMPLE_REGEX

Core regex engine with matching, replacement, and splitting operations

SIMPLE_REGEX_MATCH

Match results with groups, positions, and context

SIMPLE_REGEX_MATCH_LIST

Collection of matches with iteration support

SIMPLE_REGEX_BUILDER

Fluent API for constructing patterns programmatically

SIMPLE_REGEX_PATTERNS

Pre-built patterns: email, URL, IP, phone, date, UUID

Safety Features

Pattern validation, ReDoS detection, input escaping

Installation

<library name="simple_regex" location="$SIMPLE_REGEX\simple_regex.ecf"/>

Quick Start

local
    regex: SIMPLE_REGEX
    match: SIMPLE_REGEX_MATCH
    patterns: SIMPLE_REGEX_PATTERNS
do
    -- Basic matching
    create regex.make ("\d{3}-\d{4}")
    match := regex.match ("Call 555-1234 today")
    print (match.value)  -- "555-1234"

    -- Find all matches
    across regex.match_all ("a@b.com and c@d.org") as m loop
        print (m.value)
    end

    -- Replacement
    create regex.make ("\s+")
    print (regex.replace_all ("hello   world", " "))
    -- "hello world"

    -- Pre-built patterns
    create patterns.make
    if patterns.email.match ("user@example.com").is_matched then
        print ("Valid email%N")
    end
end

API Reference

SIMPLE_REGEX

make (pattern: STRING)
match (subject: STRING): SIMPLE_REGEX_MATCH
match_all (subject: STRING): SIMPLE_REGEX_MATCH_LIST
replace_first (subject, replacement: STRING): STRING
replace_all (subject, replacement: STRING): STRING
split (subject: STRING): LIST [STRING]
case_insensitive: SIMPLE_REGEX
multiline: SIMPLE_REGEX

SIMPLE_REGEX_MATCH

value: STRING
start_position, end_position: INTEGER
group (index: INTEGER): STRING
group_count: INTEGER
is_matched: BOOLEAN

SIMPLE_REGEX_BUILDER

literal (text: STRING): SIMPLE_REGEX_BUILDER
digit, word_char, whitespace: SIMPLE_REGEX_BUILDER
one_or_more, zero_or_more, optional: SIMPLE_REGEX_BUILDER
group, non_capturing_group: SIMPLE_REGEX_BUILDER
start_of_string, end_of_string: SIMPLE_REGEX_BUILDER
to_regex: SIMPLE_REGEX

SIMPLE_REGEX_PATTERNS

email, url, ipv4, domain: SIMPLE_REGEX
phone_us, zip_code, ssn: SIMPLE_REGEX
date_iso, date_us, date_eu: SIMPLE_REGEX
time_12h, time_24h: SIMPLE_REGEX
uuid, hex_color, username, slug: SIMPLE_REGEX
strong_password, medium_password: SIMPLE_REGEX