regex over multiple lines in Groovy

前端 未结 3 1913
南旧
南旧 2021-02-06 22:00

I have a multiple line string like following:

END IF;

EXECUTE IMMEDIATE \' CREATE INDEX #idx1
      ON somename ( row         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-06 22:28

    I had the same question and the other two answeres pointed me in the right direction. In this particular case, you want to be able to use patterns (and select groups) that span multiple lines, i.e. you want the dot to also match newline characters. Default behaviour does not match newlines. That is why you need to use the dotall (s) flag:

    /(?s)(EXECUTE).*?;/
    

    This is how you specify flags in groovy patterns.

    For testing different patterns and flags I found RegExr quite useful.

提交回复
热议问题