^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
This PM was sent by [ helloworld ] hellworld@gmail.com,
Membership Status : YES
http://gg.com.zz/US?id=gg@1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
Title : Testing is testing
Quantity : 44
Price : 55.00
Item Location : United States
*******************************************************************
I want this message right here, hello there, you help is deeply
**
appreciated :)
*** This email was sent using gg.gg.com ***
上面是我的输出字符串,我希望在长
^^^^^^-
和******
分隔符之间进行分组,最终结果将是:
This PM was sent by [ helloworld ] hellworld@gmail.com,
Membership Status : YES
http://gg.com.zz/US?id=gg@1
Title : Testing is testing
Quantity : 44
Price : 55.00
Item Location : United States
I want this message right here, hello there, you help is deeply
**^
appreciated :)
我尝试过
(?<=^)[^\^]*|[^\^-]*(?<=\*\*)
,但无法匹配整个长的^^^^^^^
分隔符,有人可以帮我吗? 最佳答案
您可以使用此正则表达式捕获所需的数据,
(?s)^(?:\^+-|\*{3,})\s*(.+?)(?=\s*(?:\^+|\*{3,}))
说明:
(?s)
-启用.
匹配换行符,这是必需的,因为要捕获的数据跨越多行^
-匹配文本的开头(?:\^+-|\*{3,})\s*
-匹配一个或多个以^
或三个结尾的-
字符(为什么是三个,所以最后一行与2星不匹配,所以最后一行不匹配)或多个*
字符,后跟可选的空白(.+?)
-匹配预期的文本并以第一个分组模式(?=\s*(?:\^+|\*{3,}))
-前瞻性确保它停止捕获数据,其后是可选的空白和上面的模式,例如^^^^^-
或*****
尽管我以前的回答也可行,但是由于它可以巧妙地捕获数据,因此效果更好。
Demo
关于ios - 正则表达式在特殊字符行之前将组分开,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54706346/