使用stringr,我试图检测字符串末尾的€符号,如下所示:
str_detect("my text €", "€\\b") # FALSE为什么这不管用?它正在处理下列案件:
str_detect("my text a", "a\\b") # TRUE - letter instead of €
grepl("€\\b", "2009in €") # TRUE - base R solution但是它在perl模式下也失败了:
grepl("€\\b", "2009in €", perl=TRUE) # FALSE那么,€\\b-regex有什么问题呢?regex €$在所有情况下都有效.
发布于 2016-12-15 23:47:55
当您使用没有perl=TRUE的基regex函数时,将使用重排香精。
这个词的边界似乎是:
见R测试:
> gsub("\\b\\)", "HERE", ") 2009in )")
[1] "HERE 2009in )"
> gsub("\\)\\b", "HERE", ") 2009in )")
[1] ") 2009in HERE"
> 这不是PCRE和ICU regex风格中字界的常见行为,在非单词字符之前的单词边界仅在字符前面有一个单词字符(不包括字符串位置的开始时匹配)(在非单词字符后面使用时,需要在单词边界后面出现一个单词字符):
有三个不同的位置被限定为单词边界:- Before the first character in the string, if the first character is a word character. - After the last character in the string, if the last character is a word character. - Between two characters in the string, where one is a word character and the other is not a word character.
https://stackoverflow.com/questions/41174959
复制相似问题