I love how it looks like a CS textbook.
Calculate the difference and intersection of any two regexes
31–40 of 127 posts
Re: Calculate the difference and intersection of any two regexes
#32(having to try them one an a time is pretty sad)
Re: Calculate the difference and intersection of any two regexes
#33The amazing page computes binary relations between pairs of regular expressions and shows a graphical representation of the DFA. It’s a really incredible demonstration of some highly non-trivial operations on regular expressions.
Re: Calculate the difference and intersection of any two regexes
#34Kinda related but I'm looking for something that could give me the number of possible matching strings for a simple regex. Does such a tool exist ?
I feel like it shouldn't be too hard to calculate from the finite automaton that encodes the regular expression, but surely in most cases it will simply be infinite?
Basically, you need an accumulator of "stuff up to here". If you move from a node to a second node, you add the character annotating that edge to the accumulator. And whenever you end up with an edge to a visited node, you add a '*' and output that, and for leaf nodes, you output the accumulator.
And then you add a silly jumble of parenthesis on entry and output to make it right. This was kinda simple to figure out with stuff like (a(ab)*b)* and such.
This is in O(states) for R and O(2^states) for NR if I recall right.
Re: Calculate the difference and intersection of any two regexes
#35Regular expressions are a great example of bundling up some really neat and complex mathematical theory into a valuable interface. Linear algebra feels similar to me.
Re: Calculate the difference and intersection of any two regexes
#36Earlier quoted context omitted.
Say you want to compute all strings of length 5 that the automaton can generate. Conceptually the nicest way is to create an automaton that matches any five characters and then compute the intersection between that automaton and the regex automaton. Then you can generate all the strings in the intersection automaton. Of course, IRL, you wouldn't actually generate the intersection automaton (you can easily do this on…
> deterministic acyclic minimized automaton That's basically a Trie right? To be fair I have only heard of them and know they can be used to do neat tricks, I've rarely used one myself.
For example, if you have words
talk
talked
talking
talks
walk
walked
walking
walks
there’s no need to repeat the “”, “ed”, “ing”, “s” parts.Re: Calculate the difference and intersection of any two regexes
#37Earlier quoted context omitted.
Say you want to compute all strings of length 5 that the automaton can generate. Conceptually the nicest way is to create an automaton that matches any five characters and then compute the intersection between that automaton and the regex automaton. Then you can generate all the strings in the intersection automaton. Of course, IRL, you wouldn't actually generate the intersection automaton (you can easily do this on…
> deterministic acyclic minimized automaton That's basically a Trie right? To be fair I have only heard of them and know they can be used to do neat tricks, I've rarely used one myself.
Re: Calculate the difference and intersection of any two regexes
#38Re: Calculate the difference and intersection of any two regexes
#39The amazing page computes binary relations between pairs of regular expressions and shows a graphical representation of the DFA. It’s a really incredible demonstration of some highly non-trivial operations on regular expressions.
It's very cool, but also no wonder that it doesn't support all those features of regexes which technically make them not regular expressions anymore. Though, I would have thought ^ and $ anchors shouldn't be a problem?
More interesting is word boundaries:
`\b` is just `\` though that should be bubbled up and usually only one side will actually produce a matchable regex.
`A\`.
Re: Calculate the difference and intersection of any two regexes
#40For example, e-mails and urls are a special syntax. Their value space is a subset of all non-empty string which is a subset of all strings.
An e-mail address could be passed into a function that requires a non-empty string as input. When the type-system knows that an e-mail string is a subclass of non-empty string, it knows that an email address is valid.
This library can be used to check the definitions and hierarchy of such string types. The implementation of the hierarchy differs per programming language (subclassing, trait boundaries, etc).