简体   繁体   中英

Multi-Line Regex

I'm trying to write a regex that can encompass a few scenarious. Mainly these:

node 'test1000.sov.local' {
include AV::AB
}

or

node 'test1000.sov.local' {
include ZY::ZT::ZZ
include AV::AB
}

or

node 'test1000.sov.local' {
include ZY::ZT::ZZ
include preinstall::global
include AV::AB
}

Theoretically it could be any number of includes under the node

This is the regex I'm attempting to use to cover this.

node\s'test1000.sov.local'\s{\n+.*\n+}

I've also tried to use

node\s'morpheustest1000.sov.local'\s{\n*.*\n}

The former doesn't really work well and the latter will only get the one include but not multiple includes.

Any help would be appreciated.

How about this expression:

/((?:node 'test1000\.sov\.local' {)(?:.*)(?:}))/s

Online Demo

  • /s will treat the string as single line. With this change change .* will match any character whatsoever, even a newline, which normally it would not match.
  • ?: the none matching group is optional here but it was added to make a single group match.
  • \\. it is also important to scape . as they have an special meaning in Regex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM