[R] regex

Ivan Krylov
Tue, 17 Sep 2019 07:25:20 -0000

On Tue, 17 Sep 2019 10:14:24 +0300
Ivan Krylov <krylov.r00t at gmail.com> wrote:

> '\\[.*\\]'

Sorry, I forgot to take it into account that you don't want the [] in
your units, either. That's still doable, but requires so-called
look-around assertions in the regular expression:

'(?<=\\[).*(?=\\])'

This should match any characters that are preceded by "[" and followed
by "]", but without including the brackets in the match. This requires
passing perl = TRUE to regexpr(). stringr::str_match() understands this
pattern without any additional flags.

--
Best regards,
Ivan