我正在尝试解析这样的ics日历文件描述
对于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.
最佳答案
事实证明,文件中的换行符顺序不同(\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修饰符。它可能跨多行匹配。而且,与惰性点匹配模式相比,性能通常要好得多。