:regexec
で
> t <- "Current CPU load - jvm machine[example network-app_svc_group_mem4]@server101.example.com"
> pattern="@([^.]+)"
> m <- regmatches(t,regexec(pattern,t))
> result = unlist(m)[2]
> result
[1] "server101"
を、することができますサブグループにアクセスする(グループの内容を取り込む)。
> result2 <- regmatches(t, regexpr("(?<[email protected])[^.]+", t, perl=TRUE))
> result2
[1] "server101"
:
はonline R demo
もう一つの方法は、試合に文字を入れていない文字の存在のためにのみチェックしますが、(?<[email protected])
後読みでregexでPCREでregmatches
/regexpr
を使用することです参照してください。
Aクリーンstringrアプローチは、同様のPCRE正規表現(同じように(ルックアラームもサポートするため)、ICU、正規表現のフレーバーを使用します)を使用することです:
> library(stringr)
> t<-c("Current CPU load - jvm machine[example network-app_svc_group_mem4]@server101.example.com")
> str_extract(t, "(?<[email protected])[^.]+")
[1] "server101"
'GSUB( '@([^。] +)|。'、 '\\ 1'、T)' – rawr