I can't seem to figure out how to match strings that contain only "%", and "§", and "#" in any order and repeated any number of times:
str <- c("%#", "#%%§§#", "§%5x#yz", "%#§", "ab§", "!#%§")
This pattern seems to get me close to the solution:
grepl("(?=[§#]*%)(?=[§%]*#)(?=[%#]*§)", str, perl = T)
[1] FALSE TRUE FALSE TRUE FALSE TRUE
Just the last match !#%§ isn't correct as the string does not only contain the character set. I see why grepl matches this string: because the last three characters are indeed the character set. So the remaining question is how to limit matches to the character set. I've tried using the anchors ^ and $, only to find no matches at all:
grepl("^(?=[§#]*%)(?=[§%]*#)(?=[%#]*§)$", str, perl = T)
[1] FALSE FALSE FALSE FALSE FALSE FALSE
What's the solution here?