Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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.



The 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


Do what? PartialMatch inserts them for you. FullMatch doesn't. The compiler can't guess your intent.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: