Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> RegExp robzijajacy na klucz = wartosc.
specialplan
post
Post #1





Grupa: Zarejestrowani
Postów: 206
Pomógł: 21
Dołączył: 1.09.2006
Skąd: Edinburgh

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


  1. <pre><?php
  2.  
  3. $input = "pOldCode='JOHNS/45354/5'
  4. nOldCode='JM'
  5. pFixedComm=595
  6. wTitle='Mrs'
  7. wInitials='J'
  8. wSurname='Fraser'
  9. vSaltn='Mr and Mrs Fraser'
  10. pFirstname1='Albert Edwin'
  11. pFirstname2='Jacqueline'
  12. wPhone='w: 732148; m: 07517223378;'
  13. vsAttn=1
  14. pAccSum='Impressive Top Floor Flat
  15. 2 Generous Bedrooms
  16. Tastefully Presented
  17. Light & Airy Lounge
  18. Splendid Fitted Kitchen
  19. G C H & Double Glazing
  20. '
  21. pLocation='On entering Culter from Aberdeen, continue straight through
  22. the village and prior to the Rob Roy Bridge, turn right at the sign for
  23. Westhill (B979) onto Malcolm Road. Proceed up and take the 3rd exit on
  24. the right. Follow this round to the very end beside the bus terminus.
  25. No 100 is situated on the right as indicated by our 'For Sale' sign.
  26. VIEWING ARRANGEMENTS:- Call Aberdein Considine & Co during office hours
  27. on 01224 734734, alternatively call Mrs Fraser on 01224 732320 or
  28. 07517223378.'
  29. pGardenNotes='NEW STYLE - A4 4photos floorplan
  30. ASPC Ref:265083'
  31. pWeekMarket=33
  32. pBrochureCode='6'
  33. pLawyerAgent='RF/JM'
  34. pSBType='P'
  35. pSBStat='FS'
  36. "; // dodaj nowa linie zeby regexp mogl zlapac ostatnia pozycje
  37.  
  38. preg_match_all( "#([a-z0-9]+)=((?:[^']+?\n)|(?:'.+?'\n))#msi", $input, $matches );
  39.  
  40. //print_r( $matches );
  41. var_dump( count( $matches[0] ) );
  42. foreach ( $matches[0] as $i => $m )
  43. {
  44.    printf( "%s --- %s\n", $matches[1][$i], $matches[2][$i] );
  45. }
  46.  
  47. // a teraz pousuwaj '' z wartosci
  48. ?>
Go to the top of the page
+Quote Post
specialplan
post
Post #3





Grupa: Zarejestrowani
Postów: 206
Pomógł: 21
Dołączył: 1.09.2006
Skąd: Edinburgh

Ostrzeżenie: (0%)
-----


Dzieki, pykam pomógł bo na oko widzę, że jest git. Potestuje jeszcze z innymi ciągami. Pzdr
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


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? (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
specialplan
post
Post #5





Grupa: Zarejestrowani
Postów: 206
Pomógł: 21
Dołączył: 1.09.2006
Skąd: Edinburgh

Ostrzeżenie: (0%)
-----


Cytat(dr_bonzo @ 2.12.2008, 23: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? (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)


Zle wkleilem:)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 2.10.2025 - 20:10