specialplan
2.12.2008, 21:19:54
Witam,
Walczyłem dziś z napisaniem wyrażenia regularnego, które rozbiłoby następujący ciąg na zestawy klucz = wartosc:
pOldCode='JOHNS/45354/5'
nOldCode='JM'
pFixedComm=595
wTitle='Mrs'
wInitials='J'
wSurname='Fraser'
vSaltn='Mr and Mrs Fraser'
pFirstname1='Albert Edwin'
pFirstname2='Jacqueline'
wPhone='w: 732148; m: 07517223378;'
vsAttn=1
pAccSum='Impressive Top Floor Flat
2 Generous Bedrooms
Tastefully Presented
Light & Airy Lounge
Splendid Fitted Kitchen
G C H & Double Glazing
'
pLocation='On entering Culter from Aberdeen, continue straight through
the village and prior to the Rob Roy Bridge, turn right at the sign for
Westhill (B979) onto Malcolm Road. Proceed up and take the 3rd exit on
the right. Follow this round to the very end beside the bus terminus.
No 100 is situated on the right as indicated by our 'For Sale' sign.
VIEWING ARRANGEMENTS:- Call Aberdein Considine & Co during office hours
on 01224 734734, alternatively call Mrs Fraser on 01224 732320 or
07517223378.'
pGardenNotes='NEW STYLE - A4 4photos floorplan
ASPC Ref:265083'
pWeekMarket=33
pBrochureCode='6'
pLawyerAgent='RF/JM'
pSBType='P'
pSBStat='FS
Ogólnie nie było by to trudne, jednak jest kilka pułapek, które wykraczają poza moje możliwości jeśli chodzi o RegExp. Nie mogę używać znaku nowej linii jako separatora, nie wszystkie wartości są ograniczone apostrofami (apostrofy też mogą występować 'wewnątrz' wartości) by wymienić kilka, myślę, że widać w przykładowym ciągu. Byłbym wdzięczny za wszelką pomoc - o ile możliwe jest napisanie jednego wyrażenia, które to obsłuży.
Pozdr
dr_bonzo
2.12.2008, 21:52:55
<pre><?php
$input = "pOldCode='JOHNS/45354/5'
nOldCode='JM'
pFixedComm=595
wTitle='Mrs'
wInitials='J'
wSurname='Fraser'
vSaltn='Mr and Mrs Fraser'
pFirstname1='Albert Edwin'
pFirstname2='Jacqueline'
wPhone='w: 732148; m: 07517223378;'
vsAttn=1
pAccSum='Impressive Top Floor Flat
2 Generous Bedrooms
Tastefully Presented
Light & Airy Lounge
Splendid Fitted Kitchen
G C H & Double Glazing
'
pLocation='On entering Culter from Aberdeen, continue straight through
the village and prior to the Rob Roy Bridge, turn right at the sign for
Westhill (B979) onto Malcolm Road. Proceed up and take the 3rd exit on
the right. Follow this round to the very end beside the bus terminus.
No 100 is situated on the right as indicated by our 'For Sale' sign.
VIEWING ARRANGEMENTS:- Call Aberdein Considine & Co during office hours
on 01224 734734, alternatively call Mrs Fraser on 01224 732320 or
07517223378.'
pGardenNotes='NEW STYLE - A4 4photos floorplan
ASPC Ref:265083'
pWeekMarket=33
pBrochureCode='6'
pLawyerAgent='RF/JM'
pSBType='P'
pSBStat='FS'
"; // dodaj nowa linie zeby regexp mogl zlapac ostatnia pozycje
preg_match_all( "#([a-z0-9]+)=((?:[^']+?\n)|(?:'.+?'\n))#msi", $input, $matches );
//print_r( $matches );
foreach ( $matches[0] as $i => $m )
{
printf( "%s --- %s\n", $matches[1
][$i], $matches[2
][$i] ); }
// a teraz pousuwaj '' z wartosci
?>
specialplan
2.12.2008, 21:56:29
Dzieki, pykam pomógł bo na oko widzę, że jest git. Potestuje jeszcze z innymi ciągami. Pzdr
dr_bonzo
2.12.2008, 22:24:40
Powiem ci co to obsluguje:
jednoliniowe bez apostrofow lub z apostrofami
wieloliniowe z apostrofami, nawet z apostrofami w srodku
pSBStat='FS --- nie obsluzy - brak konczacego apostrofu, nei wiem, ucielo ci dane, czy jak?