This is an example string:
123456#p654321
Currently, I am using this match to capture 123456
and 654321
in to two different groups:
([0-9].*)#p([0-9].*)
But on occasions, the #p654321
part of the string will not be there, so I will only want to capture the first group. I tried to make the second group "optional" by appending ?
to it, which works, but only as long as there is a #p
at the end of the remaining string.
What would be the best way to solve this problem?
question from:https://stackoverflow.com/questions/66066650/r-using-tidyrs-extract-and-regex-to-extract-values-from-structured-character