i have a Perl script which tokenize a string
@s=split /([^a-zA-Z \t\-\'\,\.]+)/, $_[0]; # tokenized with separators
so if i have a string $s="The large [[bear]] is dangerous."
it will return array("The large", " [[", "bear", "]] ", "is dangerous", ".")
But the regex pattern doesn’t seem to work when i used it on a php script.
$tokens = preg_split("/[^a-z \t\-\'\,\.]+/i", $s);
does anyone have any idea about the problem?
Got it to run (Demo):
Output:
Details:
\'is written as\\\'.PREG_SPLIT_DELIM_CAPTUREflag.See Single quoted StringsDocs and
preg_splitDocsEdit: To split at the punctuation, just remove them from the pattern (Demo):