Back-patch of commits 72dd6291f2, f6a05fd973, and 60e9c224a1. This is needed to support fixing the regex prefix extraction bug in back branches.
72dd6291f2
f6a05fd973
60e9c224a1