On Dec 26, 10:20 pm, Esmail <ebonak_de... / hotmail.com> wrote: > MonkeeSage wrote: > > On Dec 26, 4:32 pm, Esmail <ebonak_de... / hotmail.com> wrote: > >> If I have an array ar of strings that contains > >> for instance > > >> aaaa > >> bbbb > >> cccc > >> >dddd > >> eeee > >> dddd > >> cccc > >> etc. > > >> is there a way to use ar.index with a regular > >> expression to get the index of the line >dddd > > >> I've tried ar.index(/^>/) and (/^\>/) without > >> much luck. > > >> In other words, I'm trying to match on the first > >> character which is a > > > >> Thanks. > > > ['aaaa', '>bbbb', 'cccc'].find { | e | e =~ /^>/ } > > Hi Jordan, > > Is there a way to use this regular expression to return the > index value of the position where this string is found? That > is the main thing I am interested in. > > It seems there ought to be an easy way ('cept I don't know it :-) > > Esmail Hi, There's no built-in way that I'm aware of. You have to iterate over the array yourself. If you want all the indices you could something like... indices = [] ['aaaa', '>bbbb', '>cccc'].each_with_index { | e, i | indices << i if e =~ /^>/ } p indices # => [1, 2] But given the description of what you're trying to do in the other thread, you probably just want to use Array#reject... a = ['aaaa', '>bbbb', 'cccc'].reject { | e | e =~ /^>/ } p a # => ["aaaa", "cccc"] Regards, Jordan