regex - php replace comma at the end of word that ends with lowercase letter to a colon -


i have string this: 2d-digital, 1:10pm, 3:10pm, reald-3d, 5:15pm need string 2d-digital: 1:10pm, 3:10pm, reald-3d: 5:15pm

i thought using preg_replace on string find words end letter , replace , : problem 3:10pm , such end letter. please me.

you can use negative , positive look-behind find desire commas :

(?<![ap]m)(?<=[a-za-z]), 

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


Comments