在R中,如何检查字母或标点符号是否位于字符串中的指定位置?

在R中,如何检查字母或标点符号是否位于字符串中的指定位置?,r,string,R,String,假设我有两个字符串: text1 <- "Mr. JONES. The weather today is nice." text2 <- "Mr. JONES, how are you doing today?" text1这是否有帮助 grep('[^ ]+ +[^ .]+[.]', x) #[1] 1 3 或 数据 text1您可以尝试以下方法 如何检查字符是否位于第二个空格左侧的一个位置 >x grep('^[^]*[^]*\\.',x) [1] 1 琼斯右边的一个位置

假设我有两个字符串:

text1 <- "Mr. JONES. The weather today is nice."
text2 <- "Mr. JONES, how are you doing today?"
text1这是否有帮助

grep('[^ ]+ +[^ .]+[.]', x)
#[1] 1 3

数据
text1您可以尝试以下方法

如何检查字符是否位于第二个空格左侧的一个位置

>x grep('^[^]*[^]*\\.',x)
[1] 1

琼斯右边的一个位置是句号


>grep(”(?是的,因为第二个空格前的字符不是点。op就是这么问的。他想匹配第二个空格前有
的行。
grep('(?<=[A-Z]),(?= )', x, perl=TRUE)
#[1] 2
grep('JONES\\.', x)
#[1] 1 3
text1 <- "Mr. JONES. The weather today is nice."
text2 <- "Mr. JONES, how are you doing today?"
text3 <- "Mr.   JONES. The weather today is nice."
x <- c(text1, text2, text3)
> x <- c("Mr. JONES. The weather today is nice.", "Mr. JONES, how are you doing today?")
> grep('^[^ ]* [^ ]*\\. ', x)
[1] 1
> grep('(?<=JONES)\\. ', x, perl=T)
[1] 1
> grep('JONES\\K\\. ', x, perl=T)
[1] 1