[英]what is the regular expression for a blank line?
http://www.endmemo.com/program/R/grep.php
我已经在图表中查看了与空白行相对应的正则表达式,但似乎找不到它。 我已经尝试过\\\\n
但这意味着要换行,而不一定是空白。
例如 :
string = c("Precedence: bulk",
"List-Unsubscribe: <mailto:zzzzteana-unsubscribe@yahoogroups.com>",
"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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.