簡體   English   中英

空行的正則表達式是什么?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM