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
Post a Comment