文件中数字列表的正则表达式长度
regex lenght of a list of numbers from a file
你好,我想从文件中过滤一些数字,我知道的唯一方法是使用正则表达式,但返回的数组似乎是空的。这是我的 failed.txt
的样子
015-05-12 18:57:11,4, modem1: Sending SMS (part 1/2) to 40747984729 failed, trying time 98 sec. Retries: 2.
2015-05-12 19:07:13,4, modem1: Sending SMS (part 1/2) to 40731109381 failed, trying time 98 sec. Retries: 2.
2015-05-12 19:14:16,4, modem1: Sending SMS (part 1/2) to 40766368165 failed, trying time 104 sec. Retries: 2.
2015-05-12 19:17:31,4, modem1: Sending SMS (part 1/2) to 40755129209 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:20:41,4, modem1: Sending SMS (part 1/2) to 40760015914 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:23:22,4, modem1: Sending SMS (part 1/2) to 40763297631 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:28:52,4, modem1: Sending SMS (part 1/2) to 40769564718 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:39:13,4, modem1: Sending SMS (part 1/2) to 40722494529 failed, trying time 99 sec. Retries: 2.
2015-05-12 19:44:43,4, modem1: Sending SMS (part 1/2) to 40751013760 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:47:06,4, modem1: Sending SMS (part 1/2) to 40766223398 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:49:01,4, modem1: Sending SMS (part 1/2) to 40730263329 failed, trying time 106 sec. Retries: 2.
2015-05-12 19:51:25,4, modem1: Sending SMS (part 1/2) to 40784114631 failed, trying time 98 sec. Retries: 2.
2015-05-12 19:53:59,4, modem1: Sending SMS (part 1/2) to 40766844650 failed, trying time 98 sec. Retries: 2.
这是我的 php 代码,无法提取失败的号码
$regexp = '/^[0-9]{5,11}$/';
preg_match_all($regexp, file_get_contents('http://test.ro/failed.txt'), $keys, PREG_PATTERN_ORDER);
$keys = array_unique($keys);
var_dump($keys);
用单词边界替换锚点\b
$regexp = '/\b[0-9]{5,11}\b/';
你好,我想从文件中过滤一些数字,我知道的唯一方法是使用正则表达式,但返回的数组似乎是空的。这是我的 failed.txt
的样子
015-05-12 18:57:11,4, modem1: Sending SMS (part 1/2) to 40747984729 failed, trying time 98 sec. Retries: 2.
2015-05-12 19:07:13,4, modem1: Sending SMS (part 1/2) to 40731109381 failed, trying time 98 sec. Retries: 2.
2015-05-12 19:14:16,4, modem1: Sending SMS (part 1/2) to 40766368165 failed, trying time 104 sec. Retries: 2.
2015-05-12 19:17:31,4, modem1: Sending SMS (part 1/2) to 40755129209 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:20:41,4, modem1: Sending SMS (part 1/2) to 40760015914 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:23:22,4, modem1: Sending SMS (part 1/2) to 40763297631 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:28:52,4, modem1: Sending SMS (part 1/2) to 40769564718 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:39:13,4, modem1: Sending SMS (part 1/2) to 40722494529 failed, trying time 99 sec. Retries: 2.
2015-05-12 19:44:43,4, modem1: Sending SMS (part 1/2) to 40751013760 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:47:06,4, modem1: Sending SMS (part 1/2) to 40766223398 failed, trying time 103 sec. Retries: 2.
2015-05-12 19:49:01,4, modem1: Sending SMS (part 1/2) to 40730263329 failed, trying time 106 sec. Retries: 2.
2015-05-12 19:51:25,4, modem1: Sending SMS (part 1/2) to 40784114631 failed, trying time 98 sec. Retries: 2.
2015-05-12 19:53:59,4, modem1: Sending SMS (part 1/2) to 40766844650 failed, trying time 98 sec. Retries: 2.
这是我的 php 代码,无法提取失败的号码
$regexp = '/^[0-9]{5,11}$/';
preg_match_all($regexp, file_get_contents('http://test.ro/failed.txt'), $keys, PREG_PATTERN_ORDER);
$keys = array_unique($keys);
var_dump($keys);
用单词边界替换锚点\b
$regexp = '/\b[0-9]{5,11}\b/';