https://github.com/xspin/regexparser
Regular Expression Parser and Visualizer
https://github.com/xspin/regexparser
lexer regular-expression visualization
Last synced: 5 months ago
JSON representation
Regular Expression Parser and Visualizer
- Host: GitHub
- URL: https://github.com/xspin/regexparser
- Owner: xspin
- License: mit
- Created: 2025-12-03T10:03:31.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-12-25T12:01:32.000Z (6 months ago)
- Last Synced: 2026-01-13T19:45:15.404Z (5 months ago)
- Topics: lexer, regular-expression, visualization
- Language: C++
- Homepage:
- Size: 335 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RegexParser
A terminal tool to parse and visualize regular expression.
Supported Syntax: [Regular Expression Syntax](RegularExpression.md)
## Build and Install
```sh
# build
make
# install
make install
```
## Run unittest
```sh
make test
```
## Basic Usages
```sh
# Parse a specified regular expression
build/regexparser '^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$'
# Read from stdin
echo "a+b*[0-9]+" | build/regexparser
# Print ansi-colored result
build/regexparser -c '[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?'
# Generate and parse a random regular expression
build/regexparser -g 20
# Output the syntax tree
build/regexparser -g 20 -f tree
# Run as HTTP server
build/regexparser -p 8080
# Show more usage details
build/regexparser -h
```
## An Example of Text Graph Output
```
Regular Expression: ^(\-|\+)?\d+(\.\d+)?$
╭Group #1╴╮
╷ ┌─┐ ╷ ╭╴╴╴╴╴Group #2╴╴╴╴╴╮
╷ ┌─┤-├─┐ ╷ ╷ ╷
╔══^══╗ ╷ │ └─┘ │ ╷ ╔═\d══╗ ╷ ┌─┐ ╔═\d══╗ ╷ ╔═$═╗
●──╣Start╠──┬─┼─┤ ┌─┐ ├─┼─┬──┬─╣Digit╠─┬──┬─┼─┤.├──┬─╣Digit╠─┬─┼─┬──╣End╠──◎
╚═════╝ │ ╷ └─┤+├─┘ ╷ │ │ ╚═════╝ │ │ ╷ └─┘ │ ╚═════╝ │ ╷ │ ╚═══╝
│ ╷ └─┘ ╷ │ └──↻1→∞───┘ │ ╷ └──↻1→∞───┘ ╷ │
│ ╷ ╷ │ │ ╰╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╴╯ │
│ ╰╴╴╴╴╴╴╴╴╴╯ │ └─────────↺0→1─────────┘
└────↺0→1─────┘
```
## DFA States and Graph
```sh
# DFA states table and graph output
build/regexparser -fd '(a[ab]c|b[bc]c|c[ac]c)'
```
```
Regular Expression: (a[ab]c|b[bc]c|c[ac]c)
========== DFA Start ==========
Tokens: a b c
>State 0: 1 2 3
State 1: 4 4 -
State 2: - 4 4
State 3: 4 - 4
State 4: - - 8
*State 8: - - -
Accept States: 8
========== DFA End ==========
a
┌>─────┐
│ ↓
┏━━━━━┓c ╭────┴╮c ╭┴────╮c ╔═════╗
→┃ 0 ┃───>│ 3 │───>│ 4 │───>║ 8 ║
┗━━━━┬┛ ╰─────╯ ╰┬────╯ ╚═════╝
│ ↑
b│ │
┌──<┤ │
│ │a │
│ └>─────┐ │
│ │ b │
│ │ ┌>─────┤
│ │ │a │
│ │ ├>─────┤
│ c │ │ │
│ ┌>─────┼───┼──────┤
│ │b │ │ │
│ ├>─────┼───┼──────┘
↓ │ ↓ │
╭┴───┴╮ ╭┴───┴╮
│ 2 │ │ 1 │
╰─────╯ ╰─────╯
```
## Examples of SVG and HTML Format Output
[svg example](examples/example.svg)

[html example](examples/example.html)