Regexp question

Discussion in 'Ruby' started by bcparanj@gmail.com, Jul 20, 2007.

  1. Guest

    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.
    , Jul 20, 2007
    #1
    1. Advertising

  2. darren kirby Guest

    quoth the :
    > 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://badcomputer.org
    "...the number of UNIX installations has grown to 10, with more expected..."
    - Dennis Ritchie and Ken Thompson, June 1972
    darren kirby, Jul 20, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Hurrell
    Replies:
    4
    Views:
    145
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    445
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    328
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    176
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    164
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page