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

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -