I\'m still relatively new to regex. I\'m trying to find the shortest string of text that matches a particular pattern, but am having trouble if the shortest pattern is a sub
Another regex solution; it finds only the last occurence of .*a.*b.*c:
my_pattern = 'a(?!.*a.*b.*c).*b[^c]*c'
a(?!.*a.*?b.*?c)
ensures that there is no 'a.*?b.*?c'
after first 'A'
strings like A|A|B|C or A|B|A|B|C or A|B|C|A|B|C in results are eliminated
b[^c]*c
ensures that after 'B' there is only one 'C'
strings like A|B|C|B|C or A|B|C|C in results are eliminated
So you have the smallest matching 'a.*?b.*?c'