[英]What are the boolean 'regexp' for Shiny DT::datatable?
There is an option in R Shiny that allows making a search by 'regexp'. R Shiny中有一个选项,允许通过“ regexp”进行搜索。 Let say we have 2 strings to search: "Merc 230" and "Merc 280".
假设我们有2个字符串要搜索:“ Merc 230”和“ Merc 280”。 The working "OR" regexp is "Merc 230 | Merc 280".
工作的“ OR”正则表达式是“ Merc 230 | Merc 280”。 What will be working regexp for AND and NOT operators?
AND和NOT运算符将使用什么正则表达式?
library(DT)
DT::datatable(mtcars, options = list(
search = list(regex = TRUE)))
String in "Search" box of datatable: 数据表“搜索”框中的字符串:
1 - OR: Merc 230 | 1-或:Merc 230 | Merc 280 - work
Merc 280-工作
2 - AND: Merc 230 & Merc 280 - not work 2-AND:Merc 230和Merc 280-不起作用
3 - NOT: ! 3-不:! Merc 230 & Merc 280 - not work
Merc 230和Merc 280-不起作用
Thanks 谢谢
Im no regex expert but I have the following examples for you. 我不是正则表达式专家,但我为您提供以下示例。 The work with
str_detect()
from the stringr
package. 从
stringr
包使用str_detect()
工作。 I am not sure if the also work with DT::datatable
but I would expect them to. 我不确定
DT::datatable
是否也可以使用,但我希望它们能够使用。
library(stringr)
dummy <- c("Merc 220 Merc 210", "Merc 230 xxx Merc 280", "Merc 220 xxx Merc 280")
pattern1 <- "Merc 230|Merc 280"
str_detect(dummy, pattern1)
pattern2 <- "Merc 230.*Merc 280"
str_detect(dummy, pattern2)
pattern3 <- "^(?!(.*Merc 230.*|.*Merc 280.*))"
str_detect(dummy, pattern3)
The pattern .*
stands for zero or more characters of any kind. 模式
.*
代表零个或多个任何类型的字符。 ^(?!.*...)
means start of string not followed by zero or more characters of any kind and the expression you want to exclude. ^(?!.*...)
表示字符串的开头,后跟零个或多个任何类型的字符以及要排除的表达式。
To learn more about regular expressions I would recommend reading the Rstudio Cheatsheet on strings . 要了解有关正则表达式的更多信息,建议阅读有关字符串的Rstudio备忘单 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.