in reply to Set theory in regexs
Another alternative for doing this with a regexp is also quite bad:
/\bd4\b.*\bb2\b|\bb2\b.*\bd4\b/
But it gets really bad if you are looking for more than two members. Let's say we want to match "sets" containing all of c3, d4, and e5:
/\bc3\b.*(\bd4\b.*\be5\b|\be5\b.*\bd4\b) |\bd4\b.*(\bc3\b.*\be5\b|\be5\b.*\bc3\b) |\be5\b.*(\bc3\b.*\bd4\b|\bd4\b.*\bc3\b)/x
This gets so bad so fast that I won't even attempt to automate the generation of these regexen for matching larger numbers of elements [though it wouldn't be hard ;> ].
If you know that these sets never have duplicates, then a fairly simple regex has hopes of working and being not horribly slow:
my $want= qr/\b(?:c3|d4|e5)\b/; my $match= qr/$want.*?$want.*?$want/;
So $want matches any member that is one of the members that we want while $match matches a set that contains 3 members that we want. If sets contain no duplicates and we want 3 (unique) members, then $match matches what we want. If use ".*?" because I think it will be faster. YMMV.
- tye (but my friends call me "Tye")
|
|---|