首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带换行符的正则表达式匹配

带换行符的正则表达式匹配
EN

Stack Overflow用户
提问于 2010-10-11 11:10:46
回答 3查看 8.9K关注 0票数 0

如何匹配可以在任何地方换行的正则表达式?

例如,如果我尝试匹配“数千个海龟蛋”,它应该匹配以下所有情况。(甚至在单词内部有换行符的情况下也是如此。)

代码语言:javascript
复制
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.
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-10-11 11:13:20

代码语言:javascript
复制
  /thousands\s+of\s+turtle\s+eggs/

或者这个版本,以确保数千和鸡蛋不是另一个单词的一部分(如...eggsbath)

代码语言:javascript
复制
  /\bthousands\s+of\s+turtle\s+eggs\b/
票数 3
EN

Stack Overflow用户

发布于 2010-10-11 11:15:47

您可以使用标志"s“来匹配所有换行符。

如果使用正则表达式"/reptiles..*?sc/gis“,它将匹配"reptiles.sc”

你可以试试这个link

这是一个在线正则表达式编辑器

票数 0
EN

Stack Overflow用户

发布于 2010-10-11 11:18:59

使用“%s”开关。然后^$成为整个字符串的开始和结束,换行符被认为是空格。所以只要你使用\s来匹配单词之间的间隙。例如:

#thousands\sof\sturtle\seggs#si

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3903302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档