Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用phpexcel逗号或制表符分隔符读取文本文件_Regex_Preg Match_Phpexcel - Fatal编程技术网

Regex 使用phpexcel逗号或制表符分隔符读取文本文件

Regex 使用phpexcel逗号或制表符分隔符读取文本文件,regex,preg-match,phpexcel,Regex,Preg Match,Phpexcel,我必须读取带有逗号或制表符分隔符的文本文件。如果这是不可能的,请建议我任何方式阅读像reg exp或任何类似的。。 这是示例文件 Transaction Date Transaction Description Transaction Debit Transaction Credit 18/03/2014, 'POS Transaction 7400000000', 212.00, ' ', 14/03/2014,

我必须读取带有逗号或制表符分隔符的文本文件。如果这是不可能的,请建议我任何方式阅读像reg exp或任何类似的。。 这是示例文件

Transaction Date      Transaction Description      Transaction Debit Transaction Credit 
  18/03/2014,        'POS Transaction 7400000000',       212.00,         ' ',
  14/03/2014,        'POS Transaction 770000000',        202.95,         ' ',
  14/03/2014,        'POS Transaction 77631000000',      202.95,         ' ',
  14/03/2014,        'REV POS Purchase77100000000',       ' ',          202.95
  11/03/2014,        'MB - Qtel Hala TopUp 50109671 ,QTEL REF:QI3283',30.00 ' ',
  10/03/2014,        'MB - VODAFONERED35',               35.00,           ' ',
  08/03/2014,        'MB - Qtel Bill Payment 446748 , QTEL REF:QIB13295320',250.00,' ',
  03/03/2014,        'MB-Transfer from 100248417 to 100222077',   '5,000.00',   ' ',
  01/03/2014,        'POS Transaction 40501048',          207.85,    ' ',
  27/02/2014,        'TFR:000019-Payment - Automatic Loan Pymt W/D','2,880.00',' ',
  27/02/2014,        'TFR:000005-Payment - Automatic Loan Pymt W/D','2,771.00',' ',
  27/02/2014,        'ATM Withdraw 0058',                 '4,000.00',' ',
  27/02/2014,        'ATM Withdraw 0058',                 '5,000.00',' ',
  27/02/2014,        'MB-Transfer from 109812 to 10017',    ' ',     500.00
  27/02/2014,        'MB-Transfer from 10892 to 100417',    ' ',     500.00

尝试此操作以匹配所有逗号分隔的值,如果逗号位于数字之间,则将忽略

$f= file("statement.txt"); //if from text file

foreach($f as $dailystatmet)
{

         preg_match_all("/('?\d+,\d+\.\d+)?([a-zA-Z]|[0-9]|)[^,]+/",$dailystatmet,$matches);

        var_dump($matches);
}


对于制表符,将逗号替换为\t ie/'?\d+,\d+\.\d+?[a-zA-Z]|[0-9]|[^\t]+/
$dailystatmet="18/03/2014,'POS Transaction 7400000000',212.00,' ', 14/03/2014";
preg_match_all("/('?\d+,\d+\.\d+)?([a-zA-Z]|[0-9]|)[^,]+/",$dailystatmet,$matches);
var_dump($matches);