To regex after underscore in R
, you can use the sub
or gsub
function to match and replace patterns in a string.
Here's an example to extract the substring after the last underscore in a string:
195 chars10 lines
The regular expression ^.+_
matches everything before and including the last underscore. The sub
function then replaces this matched pattern with an empty string, effectively removing it from the original string.
If you want to keep the part before the underscore, you can use the strsplit
function to split the string into two parts:
209 chars10 lines
gistlibby LogSnag