Can we use sub to remove characters after ? . We use positive lookbehind ( (?<=\\?).* ) To match one or more characters ( . ) Preceded by ? and replace it with. ''
my.data$LANDING <- sub('(?<=\\?).*$', '', my.data$LANDING, perl=TRUE) my.data
Or another option is to use capture groups , and then replace the second argument with the capture group ( \\1 ).
my.data$LANDING <- sub('([^?]+\\?).*', '\\1', my.data$LANDING)
Here we match all characters that are not ? ( [^?]+ ) and then ? ( \\? ) and use parentheses to write as a group ( ([^?]+\\?) ), and we leave the rest of the characters not in the group ( .* ).
Or how @Frank mentioned in the comments can we match the character ? and other characters ( .* ) and replace it with \\? as a second argument.
my.data$LANDING <- sub("\\?.*","\\?",my.data$LANDING)
akrun source share