# Original string
original_string <- "example-string-with-symbol-in-it"

# Using regex with gsub function to remove everything before the second-last "-"
# Regex explanation:
# .*(-[^-]*-[^-]*)$ : Matches any characters up to the part just before the last "-" ensuring this part includes two "-"
# This will keep the last "-" and everything after it
result_string <- gsub(".*-([^-]*-[^-]*)$", "\\1", original_string)

# Output the result
print(result_string)
## [1] "in-it"
# Original string
original_string <- "sss_bbb_ccc"

# Using regex with sub function to remove the pattern similar to "sss_" without directly specifying "sss"
# Regex explanation:
# ^[^_]+_ : Matches any sequence of characters not including an underscore, followed by an underscore, at the beginning of the string
result_string <- sub("^[^_]+_", "", original_string)

# Output the result
print(result_string)
## [1] "bbb_ccc"