对于PCRE,这可以正常工作,但是当我尝试将其转换为iOS / ICU使用时,我得到以下结果:
let descriptionRegex = "(?m)DESCRIPTION:(.*(?:\\n :?.*)*)"
返回: "What is the purpose of the stand up meeting? \nIt is a 15 "
将此转换为ICU表达式时,我没有考虑哪些更改?
原文:
DESCRIPTION:The purpose of a retrospective meeting is to reflect on th
e previous sprint together with the development team to learn from our
mistakes. \nIs the team performing well or what can we do to improve
our way of working\, our efficiency\, and so on. \nAny topic can be di
scussed\, we strive for open communication in this meeting to continuo
usly improve as a team. \n\nWe try to list: \n - Engine
: what is working well and what do we continue doing? \n - Anchor
: what didn't we do well or what went wrong\, so what do we stop doing
or can be improved? \n - Try
: which actions do we take\, which things do we try in the next sprint
to improve? \n\nAfter the retrospective\, I want to have a look at th
e sprint plan\, to decide which user stories we work on next with the
team.
答案 0 :(得分:1)
可能会发现您的文件中有不同的换行符序列\r
或\r\n
或\n
,或者甚至是混合的。因此,您可以尝试使用\n
替换正则表达式中的\R
。
此外,如果您想在某些分隔符之间匹配一些未知数量的字符,您可以使用可以展开的(?s)DEL1(.*?)(?=DEL2)
正则表达式来获得更好的性能,具体取决于DEL2
分隔符。
以下是您的情景:
(?m)^DESCRIPTION:([^\n]*(?:\n++(?![A-Z]+:)[^\n]*)*)
请参阅regex demo
[^\n]*(?:\n++(?![A-Z]+:)[^\n]*)*
部分是(?ms).*?(?=^[A-Z]+:)
的展开版本。展开的正则表达式的优势是它不依赖于DOTALL修饰符。它可以匹配多行。此外,与懒惰点匹配模式相比,性能通常要好得多。