The monitors wanted to close this question, but I think it may be helpful to keep it since this question highlights the differences between different SQL systems (Veritica and Snowflake in this case), the exactly same expression produces different results on different platforms. Also the reg function is pretty common in db systems, but in Spark, it seems the closest function to this one is regep_extract.
On Vertica:
select regexp_substr('5,161,361,6,4,7,65,8,220,9,138' ,'^\d+(,\d+,\d+)*,161,(\d+)',1,1,'',2)
will return 361. But on Snowflake, this returns null. Could anyone help?