michaellunsford Posted January 17, 2007 Share Posted January 17, 2007 I'm wanting to capture [0-9]{0,6} but [b]exclude[/b] the zip code (7[0-9]{4}) from the result.example 1 "78876 555 easy street" should return "555"example 2 "1095012 LBJ Highway, 71231" should return "1095012"example 3 "7000 East Main Street" should return "7000"Just can't figure it out. Link to comment https://forums.phpfreaks.com/topic/34515-any-number-except-70-94/ Share on other sites More sharing options...
effigy Posted January 17, 2007 Share Posted January 17, 2007 See if this works for the rest of your dataset. I changed the max to 7 since you said "1095012" should match--it is 7 numbers, not 6.[code]<pre><?php $tests = array( "78876 555 easy street", ### should return "555" "1095012 LBJ Highway, 71231", ### should return "1095012" "7000 East Main Street" ### should return "7000" ); foreach ($tests as $test) { preg_match('/\b(?!7\d{4})\d{1,7}\b/', $test, $matches); print_r($matches); }?></pre>[/code] Link to comment https://forums.phpfreaks.com/topic/34515-any-number-except-70-94/#findComment-162592 Share on other sites More sharing options...
michaellunsford Posted January 17, 2007 Author Share Posted January 17, 2007 [quote author=effigy link=topic=122751.msg506671#msg506671 date=1169011514]I changed the max to 7 since you said "1095012" should match--it is 7 numbers, not 6.[/quote]odd, my PHP reads it like this [1]{6}=7Great it works! Now, what's the difference between [0-9] and \d? preference, or is it more than that? Link to comment https://forums.phpfreaks.com/topic/34515-any-number-except-70-94/#findComment-162594 Share on other sites More sharing options...
effigy Posted January 17, 2007 Share Posted January 17, 2007 [tt]\d [/tt]is a shortcut for[tt] [0-9][/tt]; I don't think it is affected by locales, like[tt] \w[/tt]. Link to comment https://forums.phpfreaks.com/topic/34515-any-number-except-70-94/#findComment-162616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.