GG资源网

如何迭代“1或多”项的正则表达式?

问题描述:

I am trying to develop a regular expression to read a pager message into categories. At the end are the responding brigades\' codes (CBORT, CYAND)

These brigade codes represent each responding brigade. The issue is that there can either be one eg. (CBORT) or many eg. (CBAGR, CBORT, CYAND). I am unsure how to make the regex match each brigade as an individual match.

Each brigade code will have the letter C as a prefix.

Can this be done using a regular expression or will I require a PHP script to iterate through the last part of the message to match each of these brigade codes into an array?

Pager Message:
@@ALERT BORT1 G&SC1 GRASS FIRE - SPREADING QUICKLY 79 BOORT-YANDO RD BOORT SVNW 214 J15 (475017) AFPR CBORT CYAND F190400036

Current Regex:
(@@)(ALERT)\\s(\\w+)\\s(\\S+)(C1|C3)\\s(.+)\\s(\\d+|\\d+KM|\\d+ M|CNR|NEAR|NEXT TO|ADJACENT|BEHIND|ACROSS FROM|ACROSS|REAR OF|REAR|OUTSIDE)\\s(.+)\\s(SVNW)\\s(\\d+)\\s(\\w\\d+)\\s((\\d+))\\s(F|AF|FP|AFP|AFPR|AFPRS)\\s(C\\w+)\\s(F\\d+)

The bold section is the section I wish to iterate 1 or many times.

Thank you

网友观点:

You can use ((C\\w+)\\s)+ to have at least one group that match, but capture the following ones as well.

You also need to escape the parenthesis of your message with \\( and \\) (reserved characters)

Full regex :

正则表达式上——基本语法

JavaScript 正则表达式上——基本语法

定义

JavaScript种正则表达式有两种定义方式,定义一个匹配类似 <%XXX%> 的字符串

1. 构造函数

由于网站搬家,部分链接失效,如无法下载,请联系站长!谢谢支持!
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 如何迭代“1或多”项的正则表达式?

发表回复

CAPTCHAis initialing...