Regex to find two words on the page

后端 未结 5 1824
無奈伤痛
無奈伤痛 2021-01-30 11:04

I\'m trying to find all pages which contain words \"text1\" and \"text2\". My regex:

text1(.|\\n)*text2 

it doesn\'t work..

5条回答
  •  臣服心动
    2021-01-30 11:39

    If you want the regex to match over several lines I would try:

    text1[\w\W]*text2
    

    Using . is not a good choice, because it usually doesn't match over multiple lines. Also, for matching single characters I think using square brackets is more idiomatic than using ( ... | ... )

    If you want the match to be order-independent then use this:

    (?:text1[\w\W]*text2)|(?:text2[\w\W]*text1)
    

提交回复
热议问题