【发布时间】:2021-01-21 14:39:43
【问题描述】:
我正在从 pdf 中提取行,并尝试使用 dplyr::filter(stringr::str_detect(my_column, 'my string')) 检测特定字符串。
字符串似乎没有可检测的编码。
这里是 PDF 文件的链接:https://bioconductor.org/packages/release/bioc/vignettes/Rsubread/inst/doc/SubreadUsersGuide.pdf
字符串是第 42 页表(左列)中的 em-dash。
我已尝试检测 em-dash 的几种表示形式,但在此文档中找不到。
如何确定这个 em-dash 的编码,以便我可以用它过滤我的 tibble?
pdftools::pdf_text("SubreadUsersGuide.pdf") %>%
stringr::str_split(pattern = '\r') %>%
tibble::tibble(
line = .
) %>%
tidyr::unnest(cols = line) %>%
dplyr::filter(
stringr::str_detect(line, pattern = '^EM_DASH')
)
【问题讨论】:
-
试试
pattern = '[\\p{Pd}\\xAD]',或者如果它应该在字符串的开头,pattern = '^[\\p{Pd}\\xAD]' -
嗨,@WiktorStribiżew,您提供的正则表达式确实检测到单个破折号,但没有检测到 em-dashes。
-
你的意思是
−−donotsort?那是减号,而不是破折号,使用^[\\p{Pd}\\xAD\\u2212]+,其中\u2212匹配减号。 -
我希望在第 42-43 页上提取几个(−−fracOverlap 到 −−verbose)。我希望它们都有相同的编码。成功了!