How to emulate PHPs preg_split in ruby to capture offsets and delimiters?
Posted
by dimus
on Stack Overflow
See other posts from Stack Overflow
or by dimus
Published on 2010-04-24T21:58:11Z
Indexed on
2010/04/24
22:03 UTC
Read the original article
Hit count: 203
I wonder if there is a way to get offsets and delimiters while I am splitting a string in ruby analagous to PHP preg_split:
preg_split("/( | |<|>|\t|\n|\r|;|\.)/i", $html_string, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_OFFSET_CAPTURE);
I imagine I can achieve it by traversing string by characters or using something heavy as treetop, but I would like to use something more convenient.
© Stack Overflow or respective owner