如何匹配可在任何地方发生换行的正则表达式?
例如,如果我想要匹配“数以千计的海龟蛋”,它应该符合以下所有情况。 (甚至是换行符在单词内的情况。)
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.
答案 0 :(得分:3)
/thousands\s+of\s+turtle\s+eggs/
或此版本确保数千和鸡蛋不属于另一个词(如 ... eggsbath )
/\bthousands\s+of\s+turtle\s+eggs\b/
答案 1 :(得分:0)
答案 2 :(得分:0)
使用's'开关。然后^ $成为整个字符串的开始和结束,换行符被视为空格。所以只要你使用\ s来匹配单词之间的差距。 例如:
#thousands \ SOF \ sturtle \ seggs#SI