^(?:[0369]+|[147](?:[0369]*[147][0369]*[258])*(?:[0369]*[258]|[0369]*[147][0369]*[147])|[258](?:[0369]*[258][0369]*[147])*(?:[0369]*[147]|[0369]*[258][0369]*[258]))+$
^([0369]|[147][0369]*[258]|(([258]|[147][0369]*[147])([0369]|[258][0369]*[147])*([147]|[258][0369]\*[258])))+$
I wonder if there's a shortest one.Calculate the difference and intersection of any two regexes
101–110 of 127 posts
Re: Calculate the difference and intersection of any two regexes
#102Earlier quoted context omitted.
In languages with tagged union types you do this a lot! Some Haskell pseudocode for ya module Email (Address, fromText, toText) where -- note we do not export the constructor of Address, just the type data Address = Address Text fromString :: Text -> Maybe Address fromString = -- you'd do your validation in here and return Nothing if it's a bad address. -- Signal validity out of band, not in band with the data. toTex…
Pedantic note: ‘Address’ should really be a ‘newtype’…
Re: Calculate the difference and intersection of any two regexes
#103Earlier quoted context omitted.
As ^ and $ are implicit, you can opt out of them simply by affixing `.*`.
Only when the ^ or $ were at the start/end of your string is it simple. Eg: (a|b|^)(c|d|^)foo Rewriting without ^ can require much longer regex.
((a|b)?(c|d)|c|d)?foo
Unless you mean it as a search expression, in which case it's more like ((.*a|.*b)(c|d)|c|d)?foo
Which I have to admit was a lot harder to figure out than I thought it would be (and may not even be right!)Re: Calculate the difference and intersection of any two regexes
#104Earlier quoted context omitted.
Pedantic note: ‘Address’ should really be a ‘newtype’…
Haha sorry, I get those backwards a lot. I was gonna do elm but then it’d be a conversation about why we’re writing our own email address validation on the front end instead of using the platform.
Re: Calculate the difference and intersection of any two regexes
#105Earlier quoted context omitted.
Though going from NFA to explicit DFA isn't always a good idea. Btw, you might also like looking into the Brzozowski derivative https://en.wikipedia.org/wiki/Brzozowski_derivative which can be used as an alternative way to match regular expressions.
I think it is also worth mentioning that the site linked at the top uses the antimirov extension to brzozovzki work on regex deivatives.
Re: Calculate the difference and intersection of any two regexes
#106I created a similar regex web demo that shows how a regex is parsed -> NFA -> DFA -> minimal DFA, and finally outputs LLVMIR/Javascript/WebAssembly for from the minimal DFA: http://compiler.org/reason-re-nfa/src/index.html
Though going from NFA to explicit DFA isn't always a good idea. Btw, you might also like looking into the Brzozowski derivative https://en.wikipedia.org/wiki/Brzozowski_derivative which can be used as an alternative way to match regular expressions.
Re: Calculate the difference and intersection of any two regexes
#107Kinda 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 ?
How many ways can (a?){m}(a*){m} match the string a{m}
i.e. input m repetitions of the letter 'a'.
https://github.com/mike-french/myrex#ambiguous-example
The answer is a dot product of two vectors sliced from Pascal's Triangle.
For m=9, there are 864,146 successful matches.
Re: Calculate the difference and intersection of any two regexes
#108Re: Calculate the difference and intersection of any two regexes
#109Ha, trying to paste "regex filter numbers divisible by 3" and the page froze to death https://stackoverflow.com/q/10992279/41948 ^(?:[0369]+|[147](?:[0369]*[147][0369]*[258])*(?:[0369]*[258]|[0369]*[147][0369]*[147])|[258](?:[0369]*[258][0369]*[147])*(?:[0369]*[147]|[0369]*[258][0369]*[258]))+$ ^([0369]|[147][0369]*[258]|(([258]|[147][0369]*[147])([0369]|[258][0369]*[147])*([147]|[258][0369]\*[258])))+$ I wonder if t…
(ab+c+)+
(abc){100}
a.*quick brown fox jumps over the lazy dog
Re: Calculate the difference and intersection of any two regexes
#110The 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?