in the interest of getting the as-path into one line...

^([0-9]+)?(_[0-9]+)?(_[0-9]+)?$