[英]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.