如何匹配可以在任何地方换行的正则表达式?
例如,如果我尝试匹配“数千个海龟蛋”,它应该匹配以下所有情况。(甚至在单词内部有换行符的情况下也是如此。)
Scientists have revealed that a mammoth effort to move *thousands of turtle eggs* from beaches around the Gulf of Mexico after the Deepwater Horizon oil spill may have saved almost 15,000 of the reptiles.
Scientists have revealed that a mammoth effort to move *thousands
of turtle eggs* from beaches around the Gulf of Mexico after the Deepwater Horizon oil spill may have saved almost 15,000 of the reptiles.
Scientists have revealed that a mammoth effort to move *thousands of
turtle eggs* from beaches around the Gulf of Mexico after the Deepwater Horizon oil spill may have saved almost 15,000 of the reptiles.
Scientists have revealed that a mammoth effort to move *thousands of turtle
eggs* from beaches around the Gulf of Mexico after the Deepwater Horizon oil spill may have saved almost 15,000 of the reptiles.发布于 2010-10-11 11:13:20
/thousands\s+of\s+turtle\s+eggs/或者这个版本,以确保数千和鸡蛋不是另一个单词的一部分(如...eggsbath)
/\bthousands\s+of\s+turtle\s+eggs\b/发布于 2010-10-11 11:15:47
您可以使用标志"s“来匹配所有换行符。
如果使用正则表达式"/reptiles..*?sc/gis“,它将匹配"reptiles.sc”
你可以试试这个link
这是一个在线正则表达式编辑器
发布于 2010-10-11 11:18:59
使用“%s”开关。然后^$成为整个字符串的开始和结束,换行符被认为是空格。所以只要你使用\s来匹配单词之间的间隙。例如:
#thousands\sof\sturtle\seggs#si
https://stackoverflow.com/questions/3903302
复制相似问题