Skip to content
Open

Done #25

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/regex_lab.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
def starts_with_a_vowel?(word)

word.match(/^[aiuoeAIUOE]/)? true :false
end

def words_starting_with_un_and_ending_with_ing(text)

text.scan(/\bun\w+ing\b/)
end

def words_five_letters_long(text)

text.scan(/\b\w{5}\b/)
end

def first_word_capitalized_and_ends_with_punctuation?(text)

text.match(/^[A-Z].+[.!?]$/) ? true : false
end

def valid_phone_number?(phone)

phone.match(/([0-9] *?){10}|(\([0-9]{3}\)(([0-9]{3}-[0-9]{4})|[0-9]{7})\b)$/) ? true : false
end
4 changes: 2 additions & 2 deletions spec/regex_lab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
describe "#words_starting_with_un_and_ending_with_ing" do
it "returns an array with the words starting with 'un' and ending with 'ing'" do
words_string = "unassuming ambiguous understanding pomp circumstance uninteresting uncompromising grouchy corollary"

expect(words_starting_with_un_and_ending_with_ing(words_string).count).to eq(4)
expect(words_starting_with_un_and_ending_with_ing(words_string)).to include("understanding")
expect(words_starting_with_un_and_ending_with_ing(words_string)).not_to include("pomp")
Expand Down Expand Up @@ -68,7 +68,7 @@

it "returns false for invalid phone numbers, regardless of formatting" do
valid_numbers = ["28894546", "(718)891-13135", "234 43 9978", "(800)IloveNY"]
expect(valid_numbers.all? { |number| valid_phone_number?(number) }).to be(false)
expect(valid_numbers.all? { |number| !valid_phone_number?(number) }).to be(true)
end
end

Expand Down