$re = '/(?=(?:""\s+?Controle\s*Fiscal[\w\W]+?)?""\s+(?<NomeUc>[\w\W]+?)$(?:.*?)""\s+?(?<Cnpj>\d{14})\s*(?:.*?)(?<MesReferencia>\d{2}\/\d{4})(?:.*?)(?<DtEmissao>\d{2}\/\d{2}\/\d{4})(?:.*?)\d{2}\/\d{2}\/\d{4}\s+(?<NumFatura>\d+)\s+(?:.*?)(?<ExternalCode>\d+-\d+)\s+(?:.*?)(?<DtVencimento>\d{2}\/\d{2}\/\d{4})\s+(?:.*?)(?<VlrTotalFatura>[0-9\.]+,?\d*)(?:.*?)Consta\snesta\sfatura\s*R.\s(?<VlrPisCofins>[0-9\.]+,?\d*)\sreferentes\sa\s(?:.*?)(?<AliqPis>[0-9\.]+,?\d*)%\sde\sPIS\se\s(?:.*?)(?<AliqCofins>[0-9\.]+,?\d*)%\sde\sCOFINS(?:.*?)\)\s+\d+\s+(?:\d+)?\s+(?<VlrBaseIcms>[0-9\.]+,?\d*)(?:.*?)""\s+(?<AliqIcms>\d+)\s+(?:.*?)^(?<DContratadaFp>[0-9\.]+,?\d*)\s+(?:.*?)[0-9\.]+,?\d*\s+(?<VlrIcms>[0-9\.]+,?\d*)\s+(?:.*?)""\s+(?<DataLeituraAtual>\d{2}\/\d{2}\/\d{4})\s+(?:.*?)(?<DataLeituraAnterior>\d{2}\/\d{2}\/\d{4})\s+(?:.*?)""\s+(?<LeituraAtualCFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<LeituraAnteriorCFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<ConstanteConsumoFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<CMedidoFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<LeituraAtualCP>[0-9\.]+,?\d*)\s+(?:.*?)(?<LeituraAnteriorCP>[0-9\.]+,?\d*)\s+(?:.*?)(?<ConstanteConsumoP>[0-9\.]+,?\d*)\s+(?:.*?)(?<CMedidoP>[0-9\.]+,?\d*)(?:.*?))/msu';
$str = '"" Controle Fiscal: 0B3EADFCEE1EECF867DEBB24AB24C691
"" AGUAS DE NITEROI S/A
"" ROD BR 101 KM 30,5, S/N DISTRITO CONSELHEIRO
"" 02150336000166 0704097
"" 86 41570091 0108-8
"" FAZ NOVA GAIVOT 12/2019
"" CAMPOS DOS GOYTACAZES 20/12/2019
"" 28100-000 24/12/2019
4421 Segunda Via
7889020-9 16/01/2020 2.447,37
Cons Fat Ponta 814,00 kWh2,781802.264,38
Cons Fat F Ponta 8568,00 kWh 0,541594.640,34
Dem Fat F Ponta 73,00 kW31,790002.320,67
Ajuste -4.833,30
Iluminacao Publica 126,69
ENERGIA CONSUMIDA GD BAND VERDE 6.015,70
Cred Energia Injetada G. Distribuida -6.015,70 0,00
Devolucao ICMS -2.071,41
"" 0,00
VR ADIC BAND AMARELA DO MES ( R$ 347,52 )
Consta nesta fatura R$ 533,22 referentes a 1,04% de PIS e 4,74% de COFINS
(Art. 10 Res. 298/2006-ANEEL e Leis N. 10.637/02 e 10.883/03)
33375978 9.225,39
"" 30
1.000,00 0,00 2.767,61
Tipo de Faturamento: Normal
19/12/2019 19/11/2019 19/12/2019 19/11/2019
357,00 255,00 84,000 8568,00 3555,00 2586,00 0,840 814,00
63,00 41,00 3,360 73,00 46,00 30,00 3,360 53,00
1,00 1,00 84,000 0,00 0,00 0,00 0,840 0,00
219,00 140,00 0,840 66,36 137,00 89,00 0,840 40,32
"" 13,80 kV IGOR MACHADO
"" 20/01/2020
0 0 0 0 0 THS VERDE A4 C/DES15Telefone:2716-1634
0 0 0 0 14,49 kV
0 0 E-mail:igor.santos@enel.com10/2019 Servico Publico
"" 12,83 kV 0,00%
0 0
Banco Itaú SA 341-7 34191.09008 30346.832931 83707.520009 1 81360000244737
PAGÁVEL PREFERENCIALMENTE NO ITAÚ Contra-apresentação
AMPLA Energia e Serviços S.A. 2938/37075-2
20/12/2019 4421 DP N 175/00303468-3
"" 175 2.447,37
Pagamentos efetuados após o dia 16/01/2020, incorrerão encargos financeiros de mora.
Os encargos financeiros citados, serão cobrados em faturas posteriores.
Regime Especial - processo no E-04/142.091/97
AGUAS DE NITEROI S/A
ROD BR 101 KM 30,5, S/N DISTRITO CONSELHEIRO
"" CONTA PAGA
';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php