Regex Engine Examples

February 12, 2026 ยท View on GitHub

This directory contains sample files and demos for the Lck regex engine.

Files

Sample Input Files

  • words.txt - List of common words for testing word matching patterns
  • logs.txt - Application log entries with different severity levels (ERROR, INFO, DEBUG, WARN)
  • code.txt - Python code sample for testing function/class definition matching
  • emails.txt - Email addresses in various formats (both valid and invalid)

Demo Script

  • demo.sh - Executable demo showcasing all regex features

Running the Demo

To see all examples in action:

cd examples
./demo.sh

Or from the project root:

./examples/demo.sh

Pattern Examples

1. Anchors

Match lines starting with "ERROR":

lake exe lck-grep "^ERROR" < examples/logs.txt

Match empty lines:

lake exe lck-grep "^$" < examples/emails.txt

2. Character Classes

Match lines with IP addresses:

lake exe lck-grep "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" < examples/logs.txt

Match email addresses:

lake exe lck-grep "[a-z]+@[a-z]+\\.[a-z]+" < examples/emails.txt

3. Alternation

Match lines with "cat", "dog", or "bird":

lake exe lck-grep "cat|dog|bird" < examples/words.txt

Match ERROR or WARN log levels:

lake exe lck-grep "ERROR|WARN" < examples/logs.txt

4. Wildcards

Match "a", any character, then "p":

lake exe lck-grep "a.p" < examples/words.txt

5. Repetition Operators

Plus (+) - One or more

Match words with repeated 't':

lake exe lck-grep "t+e" < examples/words.txt

Star (*) - Zero or more

Match "app" followed by any number of 'l':

lake exe lck-grep "appl*" < examples/words.txt

Question (?) - Zero or one

Match "fish" with optional "ing":

lake exe lck-grep "fishing?" < examples/words.txt

6. Function Definitions

Match Python function definitions:

lake exe lck-grep "^def" < examples/code.txt

Match class definitions:

lake exe lck-grep "^class" < examples/code.txt

Pattern Syntax Reference

SyntaxDescriptionExample
abcLiteral charactershello matches "hello"
.Any charactera.c matches "abc", "adc"
^Start of line anchor^ERROR matches "ERROR: ..."
$End of line anchorend$ matches "... end"
[abc]Character class[aeiou] matches any vowel
[a-z]Character range[0-9] matches any digit
|Alternationcat|dog matches "cat" or "dog"
*Zero or moreab*c matches "ac", "abc", "abbc"
+One or moreab+c matches "abc", "abbc" (not "ac")
?Zero or oneab?c matches "ac" or "abc"

Escape Sequences

EscapeDescription
\\nNewline
\\tTab
\\.Literal dot
\\^Literal caret
\\$Literal dollar
\\[Literal left bracket
\\]Literal right bracket
\\|Literal pipe
\\\\Literal backslash
\\*Literal asterisk
\\+Literal plus
\\?Literal question mark

Creating Your Own Examples

  1. Create a text file with sample data
  2. Use lck-grep to test patterns:
    lake exe lck-grep "pattern" < yourfile.txt
    
  3. Experiment with different pattern combinations

Tips

  • Use anchors (^ and $) to match entire lines or line boundaries
  • Character classes [...] are great for matching sets or ranges
  • Alternation | lets you match multiple patterns
  • Escape special characters with backslash \\ when you want them literal
  • The . wildcard matches any single character
  • Repetition operators (*, +, ?) apply to the preceding atom

Common Use Cases

Log Analysis

# Find all errors
lake exe lck-grep "^ERROR" < logs.txt

# Find connection issues
lake exe lck-grep "connection|timeout|failed" < logs.txt
# Find function definitions
lake exe lck-grep "^def" < code.txt

# Find variable assignments with numbers
lake exe lck-grep "[a-z]+ *= *[0-9]+" < code.txt

Data Extraction

# Find email addresses
lake exe lck-grep "[a-z]+@[a-z]+\\.[a-z]+" < data.txt

# Find IP addresses
lake exe lck-grep "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+" < data.txt