Conversation
| @@ -1,3 +1,7 @@ | |||
| def word_in_string?(word, string) | |||
| # implement with your code here | |||
| if (/(\A|\s|_|-)#{word}(\z|\s|_|-)/ =~ string).nil? | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Nice site! I threw together a quick solution. @jonahrr Try out the \b selector
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Didn't look up \b until after I posted that, that's perfect thanks
@kmodlich @maxdignan regexes are complicated