I have this regex expressions:
/^_string-(.*)-(-?[0-9]+)$/
which would match 3 parts for this example:
'_string-hello-599' ['string-hello-599', 'hello', '599']
I would like to make the last part optional -(-?[0-9]+)
, so that I could also match for example '_string-goodbye'.
This gives me 'unsafe regex' errors:
/^_string-(.*)(-(-?[0-9]+))?$/
What is the correct way to do it?