简体   繁体   中英

Regex to get content between two patterns

I'm trying to (and stumbling) write a regex that would get all the content between two patterns:

So, the patterns are like so:

/SOMEWORD:
  Lots of content
/ANOTHERWORD:

So the pattern is forwardslash, word, colon. And I want to retrieve everything in between (including new lines)

I'm just learning regex and this is a little above my skill set.

This might work if Swift regex supports \\K :

\/[^\r\n]+?:\K.*?(?=\/[^\r\n]+?:)

Just make sure the "single line" or "DOTALL" modifier is enabled; /s

https://regex101.com/r/6cNbck/1

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