Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #4207
| From | 7stud -- <bbxx789_05ss@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Generate random string matching specific pattern and length |
| Date | 2011-05-10 16:20 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <ff11e0b873337727b724da400a5e5354@ruby-forum.com> (permalink) |
| References | <BANLkTimBHzkQmhhBAb7EEX7WjXc+xzfURQ@mail.gmail.com> <BANLkTinoFJhRF8zq_AAaPkUx5OHKyakcGA@mail.gmail.com> |
Adam Prescott wrote in post #997841:
> On Tue, May 10, 2011 at 9:56 PM, Kevin <darkintent@gmail.com> wrote:
>
>> I'm trying to generate a random set of strings to fill a database with that
>> match the following pattern: /^([A-Z]|[a-z]|-)+$/
>>
>> The array I'm trying to create must contain strings that look like
>> "A12-34-4567" and be exactly ten characters long
>
>
> How's this?
>
> characters = ("A".."Z").to_a + ("a".."z").to_a # there is a shortcut to
> this
> in 1.9, but it escapes me.
> characters << "-"
>
> 10.times.map { a << b.sample }
>
> Sure there's a quicker way.
>
> By the way, /[A-Z|[a-z]|-/ is equivalent to /[A-Za-z-]/.
Of course with all your misnamed/non-existent variables, that code won't
run. Atrocious.
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Generate random string matching specific pattern and length Kevin <darkintent@gmail.com> - 2011-05-10 15:56 -0500
Re: Generate random string matching specific pattern and length Adam Prescott <adam@aprescott.com> - 2011-05-10 16:12 -0500
Re: Generate random string matching specific pattern and length 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-10 16:20 -0500
Re: Generate random string matching specific pattern and length Adam Prescott <adam@aprescott.com> - 2011-05-10 16:24 -0500
Re: Generate random string matching specific pattern and length Adam Prescott <adam@aprescott.com> - 2011-05-10 20:41 -0500
Re: Generate random string matching specific pattern and length Robert Klemme <shortcutter@googlemail.com> - 2011-05-11 02:11 -0500
Re: Generate random string matching specific pattern and length Chris Hulan <chris.hulan@gmail.com> - 2011-05-11 07:50 -0700
Re: Generate random string matching specific pattern and length Kevin <darkintent@gmail.com> - 2011-05-16 21:47 -0500
csiph-web