Shortest match in regex from end
Use negative lookahead assertion. foo(?:(?!foo).)*?boo DEMO (?:(?!foo).)*? – Non-greedy match of any character but not of foo zero or more times. That is, before matching each character, it would check that the character is not the letter f followed by two o‘s. If yes, then only the corresponding character will be matched. Why the regex … Read more