valpackett / pcre-heavy

A Haskell regular expressions library that doesn't suck | now on https://codeberg.org/valpackett/pcre-heavy
https://codeberg.org/valpackett/pcre-heavy
The Unlicense
51 stars 6 forks source link

Split retaining split pattern #15

Open Bietola opened 3 years ago

Bietola commented 3 years ago

Take this python snippet:

import re

print(re.compile(r'<.*?>').split('hello<cr>there<cr>yu<bs>ou<cr>'))

Results in the list ['hello', 'there', 'yu', 'ou']. But what if I was also interested in what kind of <.*?>s I was dealing with? I can just sorround the split regex with parenthesis (as far as I know, this is a python specific thing), like so:

print(re.compile(r'(<.*?>)').split('hello<cr>there<cr>yu<bs>ou<cr>'))

This gets you: ['hello', '<cr>', 'there', '<cr>', 'yu', '<bs>', 'ou', '<cr>'].

Is there a way to reproduce this behaviour using this library?