简体   繁体   English

使用正则表达式将字符串分割成一些字符和转义序列

[英]splitting a string in between some characters and escape sequences using a regex expression

I would just like to ask some help in constructing a regex formula for this example: 我只想在构建此示例的正则表达式公式时寻求帮助:

Brgy. Captain : Kgg. Constancia M. Reyes\nKagawad : Kgg. Henry A. Artisen\n             Kgg. Juliana S. Santos\n                Kgg. Sonia C. Alzona\n              Kgg. Fernandito L. Perez\n              Kgg. Ismael V. Capunitan\n              Kgg. Gregoria R. Sanchez\n              Kgg. Nerisa Maristañes

I am using Java in Ecplise IDE. 我在Ecplise IDE中使用Java。 I just would like to get the all the councilor names and then ignore all preceding and succeeding characters. 我只想获取所有议员名称,然后忽略所有之前和之后的字符。 This is what I would like to get: 这就是我想要得到的:

  • Kgg. gg Constancia M. Reyes Constancia M. Reyes
  • Kgg. gg Constancia M. Reyes Constancia M. Reyes
  • Kgg. gg Juliana S. Santos 朱莉安娜·桑托斯(Juliana S.Santos)
  • Kgg. gg Sonia C. Alzona 索尼娅·阿尔佐纳(Sonia C.Alzona)
  • Kgg. gg Fernandito L. Perez 费尔南迪托·佩雷斯
  • Kgg. gg Ismael V. Capunitan 伊斯梅尔诉卡皮坦坦(Ismael V.Capunitan)
  • Kgg. gg Gregoria R. Sanchez 格雷戈里亚·R·桑切斯
  • Kgg. gg Nerisa Maristañes 内莉萨·马里斯塔尼斯

Is this possible in the first place? 首先有可能吗?

I tried using this regex as i have a google chrome app then can test a regex formula but failed to match it: (Brgy. Captain :).\\\\n+(Kagawad :).\\\\n+ 我尝试使用此正则表达式,因为我有一个谷歌浏览器应用程序,然后可以测试正则表达式,但未能匹配它: (Brgy. Captain :).\\\\n+(Kagawad :).\\\\n+

如果它将始终是Kgg ,那么这应该起作用:

(Kgg.*?)(?=\\n)

The answer provided by Justin Pihony matches all of the given councilor names, but the last one. 贾斯汀·皮洪尼(Justin Pihony)提供的答案与所有​​给定的议员姓名匹配,但最后一个与之匹配。 Maybe you tried to remove everything that matches instead of preserving. 也许您尝试删除所有匹配的内容,而不是保留所有内容。

(\\n.*?)(?=Kgg)

This one is the opposite. 这是相反的。 It matches everything between. 它匹配所有之间。 But for it to work you have to add another \\n to the beginning of the list. 但是要使其正常工作,您必须在列表的开头添加另一个\\ n。

For eclipse I can recommend you the following plug-in for very fast testing of regular expressions: http://myregexp.com/eclipsePlugin.html 对于eclipse,我可以向您推荐以下插件,以非常快速地测试正则表达式: http : //myregexp.com/eclipsePlugin.html

And for basic understanding of regular expressions: http://www.regular-expressions.info/reference.html 对于正则表达式的基本了解, 请访问http : //www.regular-expressions.info/reference.html

HTH 高温超导

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM