3v4l.org

run code in 500+ PHP versions simultaneously
<?php $sentence = 'hypertext language, programming'; $keywords = preg_split('/[\s,]+/', $sentence); // ['hypertext', 'language', 'programming'] $separators = preg_split('/([\s,]+)/', $sentence, flags: PREG_SPLIT_DELIM_CAPTURE); // ['hypertext', ' ', 'language', ', ', 'programming'] $separator2s = preg_split('/([\s,])([\s]*)/', $sentence, flags: PREG_SPLIT_DELIM_CAPTURE); // ['hypertext', ' ', '', 'language', ',', ' ', 'programming'] $words = explode(' ', $sentence); // ['hypertext', 'language,', 'programming'] // comma is still collected ?>

preferences:
52.92 ms | 535 KiB | 5 Q