I wanted to extract characters after the last dash of a string. Regular expression are such a powerful tool to use in these cases. Here’s the one I needed for my problem :
Please note that with PHP, you need to use the preg_match method and surround the regexp with slashes.
preg_match ('/(\w+)[^-]*$/', 'cgo3020-red-xs', $results); // returns xs in $results
Here’s a pretty convenient tool to test your regexp: https://regex101.com/