Re: [PHP] Simple RegEx question
Find Weitz's The Regex Coach (Linux and Windows) and install it and play around. You'll learn more in one day from the pretty color syntax highlighting than reading the perl books/pages for months. On Mon, December 24, 2007 9:34 pm, M5 wrote: I'm learning regular expressions, and trying to figure out what's possible and what's not. Any ideas of how to create a preg_match expression to parse following three lines: Calgary, AB T2A6C1 Toronto, ON T4M 0B0 Saint John, NBE2L 4L1 ...such that it splits each line into City, Province and Postalcode (irrespective of occasional white space), e.g.: Array ( [city] = Calgary, [prov] = AB, [postal]= T2A 6C1 ) Array ( [city] = Toronto, [prov] = ON, [postal]= T4M 0B0 ) Array ( [city] = Saint John, [prov] = NB, [postal]= E2L 4L1 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple RegEx question
M5 schreef: I'm learning regular expressions, and trying to figure out what's possible and what's not. pretty much anything as far as string parsing goes. Any ideas of how to create a preg_match expression to parse following three lines: yes. given your intention to learn regexps why not try to come up with one? if you get stuck show us what you have so far ... you don't learn to eat with cutlery by being spoonfed. if you want to parse the whole string in one go you'll want to use preg_match_all() otherwise use preg_match and iterate over each line .. foreach(explode(\n, $data) as $line) { $matches = array(); if (preg_match($line, $regexp, $matches)) { /* do something */ } } Calgary, AB T2A6C1 Toronto, ON T4M 0B0 Saint John, NBE2L 4L1 ...such that it splits each line into City, Province and Postalcode (irrespective of occasional white space), e.g.: Array ( [city]= Calgary, [prov]= AB, [postal]= T2A 6C1 ) Array ( [city]= Toronto, [prov]= ON, [postal]= T4M 0B0 ) Array ( [city]= Saint John, [prov]= NB, [postal]= E2L 4L1 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Simple RegEx question
I'm learning regular expressions, and trying to figure out what's possible and what's not. Any ideas of how to create a preg_match expression to parse following three lines: Calgary, AB T2A6C1 Toronto, ON T4M 0B0 Saint John, NBE2L 4L1 ...such that it splits each line into City, Province and Postalcode (irrespective of occasional white space), e.g.: Array ( [city] = Calgary, [prov] = AB, [postal]= T2A 6C1 ) Array ( [city] = Toronto, [prov] = ON, [postal]= T4M 0B0 ) Array ( [city] = Saint John, [prov] = NB, [postal]= E2L 4L1 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple RegEx question
On Dec 24, 2007, at 7:34 PM, M5 [EMAIL PROTECTED] wrote: I'm learning regular expressions, and trying to figure out what's possible and what's not. Any ideas of how to create a preg_match expression to parse following three lines: Calgary, AB T2A6C1 Toronto, ON T4M 0B0 Saint John, NBE2L 4L1 ...such that it splits each line into City, Province and Postalcode (irrespective of occasional white space), e.g.: Array ( [city]= Calgary, [prov]= AB, [postal]= T2A 6C1 ) Array ( [city]= Toronto, [prov]= ON, [postal]= T4M 0B0 ) Array ( [city]= Saint John, [prov]= NB, [postal]= E2L 4L1 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Try this: $places = array(); $lines = explode(\n, $toparse); foreach ($lines as $i = $line) list($places[$i]['city'], $places[$i]['prov'], $places[$i] ['postal']) = explode(' ', $line, 3);' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple RegEx question
On Dec 24, 2007, at 7:59 PM, Casey [EMAIL PROTECTED] wrote: On Dec 24, 2007, at 7:34 PM, M5 [EMAIL PROTECTED] wrote: I'm learning regular expressions, and trying to figure out what's possible and what's not. Any ideas of how to create a preg_match expression to parse following three lines: Calgary, AB T2A6C1 Toronto, ON T4M 0B0 Saint John, NBE2L 4L1 ...such that it splits each line into City, Province and Postalcode (irrespective of occasional white space), e.g.: Array ( [city]= Calgary, [prov]= AB, [postal]= T2A 6C1 ) Array ( [city]= Toronto, [prov]= ON, [postal]= T4M 0B0 ) Array ( [city]= Saint John, [prov]= NB, [postal]= E2L 4L1 ) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Try this: $places = array(); $lines = explode(\n, $toparse); foreach ($lines as $i = $line) list($places[$i]['city'], $places[$i]['prov'], $places[$i] ['postal']) = explode(' ', $line, 3);' I'm very sorry about that, Ive been wrong all week! It doesn't parse Saint John correctly :( -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php