首页 > 解决方案 > 为什么 tidyr extract 不尊重 ignore_case 标志?

问题描述

我希望我可以将 a 传递regex给 tidyrextract并将其设置ignore_case为 true。但它显然不起作用:

tidyr::extract(
  tibble("Value"),
  col = 1,
  into = c("result"),
  regex = regex("(value)", ignore_case = TRUE)
)

这应该会产生一个包含一列result和一行 value的 tibble Value。但事实并非如此,细胞是NA.

使用大写字母时,相同的代码可以工作:

tidyr::extract(
  tibble("Value"),
  col = 1,
  into = c("result"),
  regex = regex("(Value)", ignore_case = TRUE)
)

传递ignore_case = TRUEorignore.case = TRUE直接作为参数extract并不能解决问题。

标签: rregexextracttidyversetidyr

解决方案


Thx wiktor,确实有效:

tidyr::extract(
  tibble("Value"),
  col = 1,
  into = c("result"),
  regex = "(?i)(value)"
)

推荐阅读