r - capture string between special characters -


i have string:

node<-c("current cpu load - uat_jvm1[mainnetwork-cmod_svc_group_mem1]@tt11") 

i need capture text it, "- " til "@" sign.

uat_jvm1[mainnetwork-cmod_svc_group_mem1] 

i've tried this:

str_match(node, ".*\\-+s(.*?)@.*")[,2] 

any ideas?

we can use gsub match 0 or more characters until - followed space or | @ followed other characters , replace blank ("")

gsub(".*-\\s|@.*", "", node) #[1] "uat_jvm1[mainnetwork-cmod_svc_group_mem1]" 

or if using stringr

library(stringr) str_extract(node, "(?<=-\\s)[^@]+") #[1] "uat_jvm1[mainnetwork-cmod_svc_group_mem1]" 

data

node <- c("current cpu load - uat_jvm1[mainnetwork-cmod_svc_group_mem1]@tt11") 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -