开发者

Regex matching with line breaks

How do I match a regex where a line break can happen anywhere?

For example, if I am trying to match "thousands of turtle eggs", it should match all the following cases. (or even the cases when line breaks are inside the words.)

Scient开发者_开发知识库ists 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.


  /thousands\s+of\s+turtle\s+eggs/

or this version to ensure thousands and eggs are not part of another word (like ...eggsbath)

  /\bthousands\s+of\s+turtle\s+eggs\b/


You can use the flag "s" to match all line breaks.

If you use the regex "/reptiles..*?sc/gis" it will match "reptiles.sc"

You can try this link

This is a online regex editor


use the 's' switch. Then ^$ becomes start and end of the the whole string and newlines are considered white spaces. So as long as you use \s for matching the gaps between words. eg:

#thousands\sof\sturtle\seggs#si

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜