Hard for me to say without knowing in what context it's being used and what exactly it is that you want it to do. One thing to check: since you're anchoring the regex to the start and end of the string, you might want to trim() the string first in case it has trailing newlines, spaces, etc.