#regex #dot #regular #expression #command-line-tool #testing #utility

bin+lib rxp

A command-line utility to explore and test simple regular expressions

2 unstable releases

0.2.0 Apr 14, 2022
0.1.1 Apr 9, 2022
0.1.0 Apr 9, 2022

#2335 in Command line utilities

Download history 118/week @ 2024-07-19 480/week @ 2024-07-26 174/week @ 2024-08-02 1322/week @ 2024-08-09 1809/week @ 2024-08-16 1966/week @ 2024-08-23 1648/week @ 2024-08-30 1540/week @ 2024-09-06 1509/week @ 2024-09-13 1670/week @ 2024-09-20 1007/week @ 2024-09-27 1410/week @ 2024-10-04 2641/week @ 2024-10-11 3485/week @ 2024-10-18 1936/week @ 2024-10-25 1983/week @ 2024-11-01

10,254 downloads per month

MIT license

185KB
1.5K SLoC

rxp

Rxp (Regex explorer) is a command-line utility for visualising and testing simple regular expressions. It has two subcommands, dot and test.

rxp dot <phase> <regex>

rxp dot takes a simple regular expression as text input, and outputs various abstract representations of the regex at different phases of compilation. The output format is the GraphViz dot language, which can be visualised with the dot(1) utility.

Output formats:

  • rxp dot tokens <regex>: Outputs the regular expression as a stream of tokens.
  • rxp dot ast <regex>: Outputs the regular expression as an abstract syntax tree.
  • rxp dot nfa <regex>: Outputs the regular expression as an NFA (Non-deterministic finite automaton).
  • rxp dot dfa <regex>: Outputs the regular expression as a DFA (Deterministic finite automaton).

Examples:

  • rxp dot tokens '(a|b)*cde' | dot -Tpng > tokens_example.png: Example of the rxp dot tokens command

  • rxp dot ast '(a|b)*cde' | dot -Tpng > ast_example.png: Example of the rxp dot ast command

  • rxp dot nfa '(a|b)*cde' | dot -Tpng > nfa_example.png: Example of the rxp dot nfa command Arrows marked ε are epsilon transitions, or transitions which the automaton can make without consuming any input. Arrows marked with any other unicode grapheme cluster are transitions which the automaton can make by consuming a single element of its input. This might get confusing if your test string is in Greek. Sorry!

  • rxp dot dfa '(a|b)*cde' | dot -Tpng > dfa_example.png: Example of the rxp dot dfa command

rxp test <regex> <test-string>

rxp test takes a simple regular expression and a test string to evaluate against the regex. It will print true if the test string matches the regular expression and false if it does not.

Examples:

  • rxp test '(a|b)*cde' abababcde

    true
    
  • rxp test '(a|b)*cde' ohno

    false
    

If you add the --dfa flag when testing an expression, it will be compiled to a DFA before testing, which has different performance characteristics.

Dependencies

~6–12MB
~141K SLoC