php正则表达式返回字符串中的一些整数
我需要正则表达式方面的帮助,谢谢。
我以为我已经 svn 愉快地与 Mantis 集成了,直到我遇到了包含多个问题的签入问题。我正在使用 Mantisbt 1.2.5
我试图支持的提交消息可能是这样的:“Issues #74 78 112 对第 485 行做了一些事情,只花了 3 小时 27 分钟”。我需要我的正则表达式返回 [74, 78, 112] (但不是 [485, 7, 27])。
我的“当前”$g_source_control_regexp = '/\b(bug|issue)[s]{0,1}\s*[#]{0,1}\s*(\d+\s+)+/i '
似乎返回 'Issues #74 78 112' 的 1 个元素,该元素没有更新
任何建议。
吉姆
I need help with regex, please.
I thought I had svn happily integrated with Mantis until I hit a problem with a checkin containing multiple issues. I'm using Mantisbt 1.2.5
The commit message I'm trying to support could like: "Issues #74 78 112 Did something to line 485 that only took 3 hours and 27 minutes". I need my regexp to return [74, 78, 112] (but not [485, 7, 27]).
My 'current' $g_source_control_regexp = '/\b(bug|issue)[s]{0,1}\s*[#]{0,1}\s*(\d+\s+)+/i'
seems to be returning 1 element of 'Issues #74 78 112' which updates nothing
Any advice appreciated.
Jim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为仅使用正则表达式无法做到这一点。重复捕获组仅捕获最后一次迭代(阅读有关重复捕获组与捕获重复组的更多信息< /a>)
否则我会这样做(请注意,我不是 PHP 程序员...):
(?:)
是非捕获组matches[0]
通常是完整的模式匹配matches[1]
是第一个捕获的组(在本例中是唯一的一个)trim()
来消除末尾的额外空格(没有如果你会在末尾得到一个空组 ["74", "78", "112",""])I don't think you can do that with just regex. Repeated capture groups capture just the last iteration (read more about Repeating a Capturing Group vs. Capturing a Repeated Group)
Otherwise I'd do it like this (note that I'm not a PHP programmer...):
(?:)
are non-capturing groupsmatches[0]
is usually the full pattern matchmatches[1]
is the first captured group (the only one in this case)trim()
is needed to get rid of an extra space at the end (without it you would get an empty group at the end ["74", "78", "112",""])