The answer will be
/^[a-zA-Z0-9_]+([-.][a-zA-Z0-9_]+)*$/
unless you have allowed strings containing .-and -.NOT for matching. Why would you let them fit, anyway? But if you really need these lines to match, maybe a solution
/^[a-zA-Z0-9_]+((\.(-\.)*-?|-(\.-)*\.?)[a-zA-Z0-9_]+)*$/
. - . -, . -, -. .- , , a - . , . , , , , -, . 2 . -,
/^[a-zA-Z0-9_]+((\.-?|-\.?)[a-zA-Z0-9_]+)*$/