Having trouble with match wildcards in array
Posted
by Senthil
on Stack Overflow
See other posts from Stack Overflow
or by Senthil
Published on 2010-04-20T11:44:06Z
Indexed on
2010/04/21
0:23 UTC
Read the original article
Hit count: 547
ruby
I've a master text file and exceptions file and I want to match all the words in exception file with master file and increase counter, but the trick is with wildcards.
I'm able to do without wildcards with this:
words = %w(aaa aab acc ccc AAA)
stop = %q(/aa./)
words.each do |x|
if x.match(/aa./)
puts "yes for #{x}"
else
puts "no for #{x}"
end
end
=>
yes for aaa
yes for aab
no for acc
no for ccc
yes for AAA
Also which would be the best way to go about this, using arrays or some other way.
Edit: Sorry for the confusion. Yes stop has multiple wildcards and I want to match all words based on those wildcards.
words = %w(aaa aab acc ccc AAA)
stop = %q(aa* ac* ab*)
Thanks
© Stack Overflow or respective owner