4 ms·
Improving the efficiency of your regular expressions
- dehrmann 3y ago> Using RE2::FullMatch() with leading or trailing .* is an antipattern. Instead, change it to RE2::PartialMatch() and remove the .*. This is something the compiler should do for me.
- burntsushi 3y agoDo what? PartialMatch inserts them for you. FullMatch doesn't. The compiler can't guess your intent.
- garblegarble 3y agoThe author actually touches on why it couldn't optimise this away: .* doesn't match any character sequence, it is equivalent to [^\n]* by default Also, assuming RE2 works like other engines, it also couldn't convert to a partial match without the .* prefix+suffix even if .* matched any char, because you might then ask for capture group 0