Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passes all tests #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion parser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
def word_in_string?(word, string)
# implement with your code here
if (/(\A|\s|_|-)#{word}(\z|\s|_|-)/ =~ string).nil?
Copy link

@maxdignan maxdignan May 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe look into a simpler way to do this regex. Remember, you only need to check for whitespace before and after the word (or nothing on either (or both) sides). http://regexone.com/lesson/whitespaces

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are not already using something like this http://rubular.com/ go ahead and give it a try. Unless the regex is simple you probably won't be getting it right on the first time you write it, there are many websites that allow you to test your regex on the fly its also great for learning.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice site! I threw together a quick solution. @jonahrr Try out the \b selector

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! My impression from the question was that dashes, underscores, and the beginning or end of a string are also valid delimiters, which is why the regex is complicated as it is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look up \b until after I posted that, that's perfect thanks

:no
else
:yes
end
end