regex - Normalize sentence punctuation in php? -


i have lots of input sentences want normalize. have in common don't have spaces after commas , periods.

oval,delicate cupcakes.very tasty.enjoy.

what quickest way normalize such sentences?

you can use:

$sentence = preg_replace('/([,.])(?!\s)/', '$1 ', $sentence); 
  • [.,] - match either dot or comma
  • ([.,]) - match , group backreference
  • (?!\s) negative lookahead means match if not followed space

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -