0

I am working in Ruby. I need to create a regex that takes in a string, I suppose, and returns an array with only the words that start with "un" and end with "ing". I have no clue how to do it :/

def words_starting_with_un_and_ending_with_ing(text)
  !!text.capitalize.scan(/\A+UN\Z+ING/)
end

1 Answer 1

5

Something like this:

def uning string
  string.scan(/\b[Uu]n[a-z]*ing\b/)
end

See String#scan for more info. For a nice interactive introduction to Regex take a look at RegexOne.

Sign up to request clarification or add additional context in comments.

2 Comments

@CarySwoveland, agreed on both counts. Have updated answer ty.
Thanks for the website too, it looks like an excellent resource!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.