Coming from this SO post: https://stackoverflow.com/a/36760050
The regex
^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$
got optimized (by hand) to:
^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$
so, partbefore(\.(?!$)|$))$ can be expressed as (partbefore\.?\b)$, avoiding the negative look-ahead, making the regex smaller.
Maybe worth adding as optimization?