r - gsub replace text after set of characters -


i have lot of error messages trying clean up.

some of errors end text "(sec): 0.xxx" i'm trying use gsub remove after (sec)

data$message <- gsub("(sec).*", "", data$message, perl = true) 

this returns after (

i know easy use ":" or ")" effects other errors not want change.

is there way use gsub @ several characters -like "(sec)"- instead of one? on related note symbol represents number (excludes text) similiar "."?

you can use regex look behind ?<= avoid sec being removed , @ same time assert removed pattern follows sec, (?<=sec\\)).* remove after sec) not sec) itself:

gsub("(?<=sec\\)).*", "", "(sec): 0.xxx", perl = true) # [1] "(sec)" 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -