I have a line containing many underscores followed by ex: " Field_4_txtbox " I need to find the last underscore in the line and delete everything after it (including "_"), so it will return to me " Field_4 ", but I need this to work for strings with different lengths. So I canβt just crop a fixed length.
I know that I can execute the If statement, which checks for certain endings, such as
if(strstr($key,'chkbox')) { $string= rtrim($key, '_chkbox'); }
but I would like to do it at a time with a regex pattern, how can I do this?
source share