I want to replace any word which contains two capital letters .
here is my string
jennie-garth-jennie-garth-inner-city-arts-gala-october-17-2012-If9aSpTW
jennie-garth-jennie-garth3892-H9rDcbY
i want to replace -If9aSpTW with -
These -If9aSpTW
varies so I can't use str_replace
. I can identify with only two capital letter in one word. These words are at the end, but these types of words are appearing for 20% of total database values so I can't replace all last words.
explode("-", $val)
and thenimplode
leaving out the last chunk? Or justsubstr($s, 0, strrpos( $s, '-'));
. It might be enough. You mentioned that these appear at the end of the string, what makes them specific? More than one capital letter? – Wiktor Stribiżew$result = preg_replace('/-(?:[^-]*[A-Z]){2,}[^-]*$/', '', $str);
. See this regex demo. – Wiktor Stribiżew