Php: regex get all numbers before colon

Filip

I have the folling string:

$string = "16,1-5,22-27&22:1&4:3"

I want to get all numbers before the colon and return an array with them. So for the given string i would get the following:

array(22,4)
anubhava

You can use this lookahead based regex in preg_match_all:

\d+(?=:)

Code:

$str = "16,1-5,22-27&22:1&4:3"; 

preg_match_all('/\d+(?=:)/', $str, $matches);
print_r($matches[0]);

RegEx Demo

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Regex - Match all numbers until character

来自分类Dev

Get the word right before the coma with javascript and regex?

来自分类Dev

PHP cUrl get all integrated variables data

来自分类Dev

PHP-regex / preg_match_all(child)简码属性

来自分类Dev

Rust regex replace_all比PHP regex preg_replace_callback慢,如何优化?

来自分类Dev

Implementing regex in comma separated numbers

来自分类Dev

PHP Regex preg_match_all div ID不相同

来自分类Dev

PHP:RegEx 无法匹配使用 file_get_contents 检索的 HTML 页面

来自分类Dev

Javascript regex that matches dot as punctuation only, no numbers

来自分类Dev

Check regex for letters numbers and underscore characters

来自分类Dev

Get :NEW table in BEFORE DELETE

来自分类Dev

regex to replace all tokens not in quotes?

来自分类Dev

PHP regex漏洞押注

来自分类Dev

PHP修改RegEx

来自分类Dev

PHP Regex跳上新线

来自分类Dev

PHP regex网址匹配

来自分类Dev

PHP Regex替换标签

来自分类Dev

PHP regex贪婪问题

来自分类Dev

PHP Regex模式混乱

来自分类Dev

Textarea中的PHP RegEx

来自分类Dev

PHP Regex获取最后的“ /”或“ \”

来自分类Dev

PHP阵列中的RegEx

来自分类Dev

PHP Regex不匹配

来自分类Dev

在视图测试中,何时使用before(:all)?

来自分类Dev

在before(:all)中动态添加方法

来自分类Dev

php multiple file uploads get the exact count of files a user uploaded and not the count of all input fields in the array

来自分类Dev

将JQuery RegEx转换为PHP RegEX

来自分类Dev

使用PHP将regex替换为regex

来自分类Dev

PHP Regex Facebook视频ID