为什么我的模式在非用户换行符处停止?
Why does my pattern discontinue on non-user line breaks?
我正在尝试像这样解析 ics 日历文件描述
对于 PCRE 这很好用,但是当我尝试将其转换为 iOS/ICU 使用时,我得到以下结果:
let descriptionRegex = "(?m)DESCRIPTION:(.*(?:\n :?.*)*)"
Returns: "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]*)*)
[^\n]*(?:\n++(?![A-Z]+:)[^\n]*)*
部分是 (?ms).*?(?=^[A-Z]+:)
的展开版本。 展开正则表达式的优点是它不依赖于 DOTALL 修饰符。它可能匹配多行。此外,与惰性点匹配模式相比,性能通常要好得多。
我正在尝试像这样解析 ics 日历文件描述
对于 PCRE 这很好用,但是当我尝试将其转换为 iOS/ICU 使用时,我得到以下结果:
let descriptionRegex = "(?m)DESCRIPTION:(.*(?:\n :?.*)*)"
Returns: "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]*)*)
[^\n]*(?:\n++(?![A-Z]+:)[^\n]*)*
部分是 (?ms).*?(?=^[A-Z]+:)
的展开版本。 展开正则表达式的优点是它不依赖于 DOTALL 修饰符。它可能匹配多行。此外,与惰性点匹配模式相比,性能通常要好得多。