Yes, “I shouldn’t have X” is “x するんじゃなかった” in Japanese. That’s correct. We usually use it in the verbal sentence with んじゃない present tense of んじゃなかった. Also, this んじゃなかったexpression is tend to be used in talking to myself. Sometimes we say “xするべきじゃなかった” in verbal, since “should not= べきじゃない, べきではない( a little more formal)” We use “xするべきではなかった“ in both verbal and writing.
Another way to express to regret, “x しなきゃよかった” “xしなければよかった”
For example, I should not tell him. 彼に言わなきゃよかった。more formal, 彼に言わなければよかった。