Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Regexp question
bcparanj@gmail.com
7/20/2007 7:37:00 PM
I have a list of zip codes (3000). Is there any script that I could
use to create a regexp for checking if a user entered zip is in this
list or not? TIA.
1 Answer
darren kirby
7/20/2007 8:23:00 PM
0
quoth the bcparanj@gmail.com:
> I have a list of zip codes (3000). Is there any script that I could
> use to create a regexp for checking if a user entered zip is in this
> list or not? TIA.
Doubtful you need a regexp. Answer depends on the format of your list. If it
is a separate file with one code per line you could do:
codes = IO.readlines("/path/to/codes").each { |line| line.chomp! }
codes.include?(90210.to_s)
or if you have ZIP + 4 codes:
codes.include?("90210-1234")
-d
--
darren kirby :: Part of the problem since 1976 ::
http://badco...
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Regexp question
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password