首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的模式在非用户中断时停止?

为什么我的模式在非用户中断时停止?
EN

Stack Overflow用户
提问于 2016-02-09 13:36:56
回答 1查看 40关注 0票数 0

我正试图解析ics日历文件的描述,如下所示

对于PCRE,这很好,但是当我尝试将它转换为iOS/ICU使用时,我得到了以下结果:

代码语言:javascript
复制
let descriptionRegex = "(?m)DESCRIPTION:(.*(?:\\n :?.*)*)"

返回:"What is the purpose of the stand up meeting? \nIt is a 15 "

当将此转换为ICU表达式时,我没有考虑哪些更改?

原文:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-09 14:01:01

结果可能是文件中有不同的换行符序列(\r\r\n,或者只是\n,甚至是混合的)。因此,您可以尝试用\R替换正则表达式中的\R

此外,如果您希望在某些分隔符之间匹配一些未知数目的字符,则可以使用可以展开的(?s)DEL1(.*?)(?=DEL2)正则表达式,以便根据DEL2分隔符获得更好的性能。

这里有一个用于您的场景:

代码语言:javascript
复制
(?m)^DESCRIPTION:([^\n]*(?:\n++(?![A-Z]+:)[^\n]*)*)

请参阅regex演示

[^\n]*(?:\n++(?![A-Z]+:)[^\n]*)*部件是(?ms).*?(?=^[A-Z]+:)的展开版本。展开正则表达式的优点是,不依赖于DOTALL修饰符。它可以跨越多条线进行匹配。另外,与惰性点匹配模式相比,性能通常要好得多。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35293487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档