in case we want to leverage unglue's syntax for other functions.
Need a name :
unglue_regex ?
unglue_to_regex ?
if the output is just a regex pattern there is loss of information (group names).
So a general version would give this sort of output :
x <- unglue_regex("{hello} {world}")
identical(x, list(list(regex = "(.*?) (.*?)", groups = c(hello = 1, world = 2))
Maybe the latter is annoying, because you get a list of one element if you only feed one string, then it's nested, and you might not care about groups most of the time...
So we can instead attach groups as attributes :
x <- unglue_regex("{hello} {world}")
x == "(.*?) (.*?)"
identical(attributes(x) , list(groups = c(hello = 1, world = 2))
Against the latter is that attributes are easily stripped, a call to c is enough, but I think in that case one wants them they can easily fetch them right after the call.
A function going the other way should be possible too, but maybe not that useful
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
in case we want to leverage unglue's syntax for other functions.
Need a name :
unglue_regex
?unglue_to_regex
?if the output is just a regex pattern there is loss of information (group names).
So a general version would give this sort of output :
Maybe the latter is annoying, because you get a list of one element if you only feed one string, then it's nested, and you might not care about groups most of the time...
So we can instead attach groups as attributes :
Against the latter is that attributes are easily stripped, a call to
c
is enough, but I think in that case one wants them they can easily fetch them right after the call.A function going the other way should be possible too, but maybe not that useful