Check out example codes for "r extract everything before character". It will help you in understanding the concepts better.

Code Example 1

library(stringr)
str = c("1", "1_ghfjv", "1")
str_extract(string = str, pattern = "[^_]"))

Learn ReactJs, React Native from akashmittal.com