Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression refactoring

Tags:

regex

Is there such thing as automated regular expression refactoring?

I'm wondering whether there is an online service or utility that can understand and simplify and/or optimise a regex.

e.g.

^[A-Z][A-Z][0-9][0-9][0-9]$^[A-Z]{2}[0-9]{3}$

(Obviously this is an abstract example)

like image 958
gjb Avatar asked Jan 23 '26 16:01

gjb


1 Answers

Regular expressions are automata, you can use an algorithm designed to build deterministic finite automaton, it will refactor the original automaton to a simpler one.

I do not know a programming language implementation but you can get inspired with Nondeterministic finite automaton Wikipedia page.

like image 72
sinsedrix Avatar answered Jan 27 '26 00:01

sinsedrix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!