#
#	Regular expression pattern examples
#
#pattern="[^b]*b[^b]*b[^b]*b[^b]*$" #contains 3 b's, may not be consecutive.
#pattern = ["^c[aouei][a-z]*$"]	#starts with c, followed by one vowel,and any number of letters 
#pattern << "ruby"	#contains "ruby"
#pattern << "s{3}|c{3}" #contains sss or ccc
#pattern = ["^c[aouei][a-z]*$"] #starts with c, a wovel , and any letter any number of times
#pattern << "ruby"  #contains ruby
#pattern << "(ab){2}" #contains 2 ab
#pattern << "b{2}"  #contains 2b
#pattern = "^a[a-z]?$"  #starts with a, 0 or 1 letter after that
#pattern = "(ab|ba)+" # contains one or more ab or ba
#pattern = "^ste(ve|phen|ven)$"  #steve, steven, or stephen
#pattern = ^ste(ve|phe|)n?$		#steve, steven, or stephen
#pattern = "^(..)*$"   #even length string
#pattern = "^([^aouei]*[aouei][^aouei]*[aouei][^aouei]*)*$"  #even number of vowels
#| (^[^b]+(b+[^b])*0)

#create a regular expression object
# re = Regexp.new("^" + "a" )

#open file
file="war_peace.txt"
fp = open(file)
cnt = 0
pattern = "^(b[a-z]*[^b])$|^([^b][a-z]*b)$"  #starts with b or ends with b, but not both. baa, acb match, bqaaaab no match
while line =  fp.gets do
    words = line.split(/[<>\/,?!.\s'\-()":;*]/)  #split each line into a words array
    words.each{|word| 
      word.downcase!
      if(word.match(/#{pattern}/))
        print word,"\n"
        cnt += 1
      end
        exit if cnt >  100	#display only first 100 matches
    }
end
