PHP - Help needed to remove last portion of a string
Discuss Help needed to remove last portion of a string in the Regex Programming forum on Dev Shed. Help needed to remove last portion of a string Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
Posts: 11
Time spent in forums: 5 h 6 m 17 sec
Reputation Power: 0
PHP - Help needed to remove last portion of a string
I'm a total n00b to regex and I have been working for hours on this and cannot get anything to work as I'd like.
I need to remove the last part of a string that occurs after (and including):
Code:
_x_
The remaining characters are all lower case and underscores.
eg.
elaphe_guttata_x_elaphe_guttata_emoryi
needs to be:
elaphe_guttata
My first thoughts are to use preg_replace() with an empty string for the replace part but really struggling with the expression to use. Any help is greatly appreciated