Skip to main content

Split a string

T-Regx also allows to split a string by regular expression.

pattern('[ ,]{2}')->split('Joffrey, Cersei, Ilyn Payne, The Hound');
['Joffrey', 'Cersei', 'Ilyn Payne', 'The Hound']

Including the delimiter#

To include a delimiter in the results, enclose it with a capturing group.

pattern('([ ,]{2})')->split('Joffrey, Cersei, Ilyn Payne');
['Joffrey', ', ', 'Cersei', ', ', 'Ilyn Payne']
Last updated on