简体   繁体   English

正则表达式获取两种模式之间的内容

[英]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 :如果 Swift 正则表达式支持\\K这可能会起作用:

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

Just make sure the "single line" or "DOTALL" modifier is enabled;只需确保启用“单行”或“DOTALL”修饰符; /s

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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