Regex - Can you return the matched pattern using sub?


Can I replace a pattern in a string with “” but also return the matched pattern?

Basically I am extracting different blocks of text from a string using match_pattern() but then at the end, I want to search all the remaining text (minus the blocks that were already extracted).

I tried simply calling gsub(data, pattern, “”) just after calling block[n] = match_pattern(data, pattern) but this didn’t seem to benefit performance at all. I’m sure there must be a better way :confused:

Thanks in Advance,