Php replace the comma at the end of a word that ends with a lowercase letter into a colon

I have a line like this: 2D-Digital, 1:10PM, 3:10PM, RealD-3D, 5:15PM

I need a line like this2D-Digital: 1:10PM, 3:10PM, RealD-3D: 5:15PM

I thought about using preg_replace on the string to find words that end with a letter and then replace ,

with :

, but the problem with that is 3:10 PM and also the end with a letter. Please help me.

+3


source to share


1 answer


You can use negative and positive look and feel to find commas:

(?<![AP]M)(?<=[a-zA-Z]),

      



see demo https://regex101.com/r/hD7bE6/2

+1


source







All Articles