Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

regex

Name: sage 2012-01-11 18:23

Is there a common regex notation for "at least one of each?"

For example, I want to specify that a string must contain "a", "b", and "c" in any order.  So these are all matched:


"abcabcabcbacbacb"
"acb"
"aaabbbccc"
"cba"
"cccbbbaaa"


but not "ab" or "aaaaaaaaaaaabbbbbbb".

Similarly, how about "exactly one of each" so that one_of_each("a" "b" "c") would match


abc
acb
bca


but not "aabc" or "aaaaa"?

Name: sage 2012-01-12 1:00

>>13,15
Strange, it turns out that a & b & c is actually quite hard to implement.  Maybe that's why it's uncommon.

Implementing a | b | c is easy.  I use a tree structure where each node has up to two children.  So a | b | c essentially becomes (a | b) | c.  But with a & b & c, you can't reduce that to (a & b) & c, because it's not semantically the same.  For example, the string "acb" would not match that tree because it does not contain a substring that satisfies (a & b).  Ho hum.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List