http://www.endmemo.com/program/R/grep.php
我在图表中查看了与空白行相对应的正则表达式,但似乎找不到它。我已经尝试过了,\\n
但这意味着换行,而不一定是空白。
例如:
string = c("Precedence: bulk",
"List-Unsubscribe: <mailto:[email protected]>",
"Content-Transfer-Encoding: 7bit",
"",
"Martin A posted:",
"Tassos Papadopoulos, the Greek sculptor behind the plan, judged that the",
" Mount Athos monastic community, was ideal for the patriotic sculpture. ",
" ",
" As well as Alexander's granite features, 240 ft high and 170 ft wide, a",
"planned",
"---------------------",
"So is this mountain limestone or granite?")
因此,第4行和第8行为空,我想grep
返回这些索引。
在R中,您需要转义反斜杠,所以应该这样^\\s*$
。您也可以使用^[[:space:]]*$
。
grepl("^[[:space:]]*$", c("", " ", "\t"))
# [1] TRUE TRUE TRUE
grep("^[[:space:]]*$", string)
# [1] 4 8
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句