Why is this simple .*? non-greedy regex being greedy?
问题 I have a very simple regex similar to this: HOHO.*?_HO_ With this test string... fiwgu_HOHO_HOHO_HOHOrgh_HOHO_feh_HOHO___HO_fbguyev I expect it to match just _HOHO___HO_ (shortest match, non-greedy) Instead it matches _HOHO_HOHO_HOHOrgh_HOHO_feh_HOHO___HO_ (longest match, looks greedy). Why? How can I make it match the shortest match? Adding and removing the ? gives the same result. Edit - better test string that shows why [^HOHO] doesn\'t work: fiwgu_HOHO_HOHO_HOHOrgh_HOHO_feh_HOHO_H_O_H_O