preg_split / strtok don't quite do what I need
Posted: Thu Jan 22, 2009 12:00 am
I'm trying to split a string with a regular expression (for my template engine), but keep what was in the regular expression in the result. For instance, let's assume we're parsing the string
preg_split doesn't provide a way to return the delimiters with the results
any suggestions on how I might be able to accomplish this?
it's a bummer, this is the default behavior of python's re.split() method but I can't find a way to do it in php
I want to split it with this regular expression "/([{}[]])/" and get this as the result:the string wrote:{ i am between curly brackets } and im between nothing [ and im between square brackets ] and I am between nothing too
Code: Select all
array(
'{',
' i am between curly brackets ',
'}',
' and im between nothing ',
'[',
' and im between square brackets ',
']',
' and I am between nothing too'
)it's a bummer, this is the default behavior of python's re.split() method but I can't find a way to do it in php