...

View Full Version : Regex across multiple lines



MrBiggZ
12-05-2010, 07:48 PM
Greetings!

I always have trouble with these! Going across multiple lines, grrrrr!

I concocted this regex:


#.*Type\("(.*?)"\).*Name\("(.*?)"\).*Street\("(.*?)"\).*City\("(.*?)"\).*State\("(.*?)"\).*PostalCode\("(.*?)"\).*AtmType\("(.*?)"\).*LatLng\("(.*?)","(.*?)\)#s

To search multiples of these type of data (of which I attached a portion of the file I'm using --> 9161 <-- :


dmRecord.setDistance("0.15");
dmRecord.setType("ATM");
dmRecord.setId("VS076607");
dmRecord.setName("CVS");

dmRecord.setStreet("105 E OHIO ST");

dmRecord.setCity("INDIANAPOLIS");
dmRecord.setState("IN");
dmRecord.setPostalCode("46204");

dmRecord.setItemNumber("5");



dmRecord.setAtmType("Walk Up");


dmRecord.setAtmFunctionality("Cash");





dmRecord.setAtmLanguages("English<BR/>Spanish");





dmRecord.setHoursOfOperation("24 hours a day");

dmRecord.setMQLatLng(new MQA.LatLng("39.769859","-86.15601"));
results.push(dmRecord);

dmRecord = new DataManagerRecord();

Regex was made to punish me .. I know it!

Thanks for your help! Getting better at this .. just this multi line ones throw the monkey wrench into the works! =(

MrBiggZ
12-05-2010, 09:30 PM
Testing even further It works .. but .. when I apply it against the whole file it fizzles!


<?php
$ptn = "#Type."(.*?)".*?Name."(.*?)".*?Street."(.*?)".*?City."(.*?)".*?State."(.*?)".*?PostalCode."(.*?)".*?AtmType."(.*?)".*?LatLng."(.*?)","(.*?)"#s";
$str = " dmRecord.setDistance("0.56"); dmRecord.setType("ATM"); dmRecord.setId("PW2173"); dmRecord.setName("INDIANS BASEBALL STADIUM"); dmRecord.setStreet("501 W MARYLAND"); dmRecord.setCity("INDIANAPOLIS"); dmRecord.setState("IN"); dmRecord.setPostalCode("46255"); dmRecord.setItemNumber("13"); dmRecord.setAtmType("Walk Up"); dmRecord.setAtmFunctionality("Cash"); dmRecord.setAtmAudible("Y"); dmRecord.setAtmLanguages("English<;BR/>;German<;BR/>;Italian<;BR/>;Japanese<;BR/>;Korean<;BR/>;Polish<;BR/>;Portuguese<;BR/>;Spanish"); dmRecord.setPinChagneAvail("Y"); dmRecord.setPersonalizationAvail("Y"); dmRecord.setHoursOfOperation("24 hours a day"); dmRecord.setMQLatLng(new MQA.LatLng("39.765871","-86.168114")); results.push(dmRecord); dmRecord = new DataManagerRecord(); dmRecord.setDistance("0.59"); dmRecord.setType("ATM"); dmRecord.setId("PW2167"); dmRecord.setName("HALL OF CHAMPIONS"); dmRecord.setStreet("700 W WASHINGTON"); dmRecord.setCity("INDIANAPOLIS"); dmRecord.setState("IN"); dmRecord.setPostalCode("46204"); dmRecord.setItemNumber("14"); dmRecord.setAtmType("Walk Up"); dmRecord.setAtmFunctionality("Cash"); dmRecord.setAtmAudible("Y"); dmRecord.setAtmLanguages("English<;BR/>;German<;BR/>;Italian<;BR/>;Japanese<;BR/>;Korean<;BR/>;Polish<;BR/>;Portuguese<;BR/>;Spanish"); dmRecord.setPinChagneAvail("Y"); dmRecord.setPersonalizationAvail("Y"); dmRecord.setHoursOfOperation("24 hours a day"); dmRecord.setMQLatLng(new MQA.LatLng("39.767174","-86.169131")); results.push(dmRecord); dmRecord = new DataManagerRecord(); dmRecord.setDistance("1.2"); dmRecord.setType("ATM"); dmRecord.setId("PW2213"); dmRecord.setName("UNIVERSITY HOSPITAL"); dmRecord.setStreet("1100 W MICHIGAN"); dmRecord.setCity("INDIANAPOLIS"); dmRecord.setState("IN"); dmRecord.setPostalCode("46202"); dmRecord.setItemNumber("15"); dmRecord.setAtmType("Walk Up"); dmRecord.setAtmFunctionality("Cash"); dmRecord.setAtmAudible("Y"); dmRecord.setAtmLanguages("English<;BR/>;German<;BR/>;Italian<;BR/>;Japanese<;BR/>;Korean<;BR/>;Polish<;BR/>;Portuguese<;BR/>;Spanish"); dmRecord.setPinChagneAvail("Y"); dmRecord.setPersonalizationAvail("Y"); dmRecord.setHoursOfOperation("24 hours a day"); dmRecord.setMQLatLng(new MQA.LatLng("39.774636","-86.179131")); results.push(dmRecord); dmRecord = new DataManagerRecord();";
preg_match_all($ptn, $str, $matches);
print_r($matches);
?>

That works. I changed my regex statement a little bit too


$regex = '#Type."(.*?)".*?Name."(.*?)".*?Street."(.*?)".*?City."(.*?)".*?State."(.*?)".*?PostalCode."(.*?)".*?AtmType."(.*?)".*?LatLng."(.*?)","(.*?)"#s';

Frustrating! :mad:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum