This is a follow-on to an earlier question. This question amends the question to the original intent and increases complexity by adding the requirement that the regex work with substrings.
I am looking for a way to use python regular expressions to match groups of characters with limits on how many times a character can appear in the match. The main problem is that the order of characters does not matter.
I would like to find a simple and extensible pattern for saying things like:
In which case the following substrings match:
AAAA AAAB AAAC AAAD AABA AABB AABC AABD AACA AACB AACC AACD AADA AADB AADC ABAA ABAB ABAC ABAD ABBA ABBB ABBC ABBD...
and the following substrings would not match:
CCCC DDDD DDDA DDAA DDAB ...
I put the match list here.
Is there a pattern for this type of match that doesn't involve listing all possible combinations?
use this pattern to match your criteria as a sub-string
(?!B{4})(?!C{4})(?!([ABC]?D){2})[A-D]{4}
(?!B{4}) # does not see 4B's
(?!C{4}) # does not see 4C's
(?!([ABC]?D){2}) # does not see 2D's in any order
[A-D]{4} # [A-D] 4 times
Edit:
After reading comments below, give this pattern a try:
(?!B{4})(?!C{4})((?!.?.?DD|.?D.D|D..D)[A-D]{4})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句