"hello world this is me !".scan(/\b[\w']+\b/) { |word| puts word }
The above code will scan for a pattern of
1. word boundary
2. 1 or more word character plus '
3. another word boundary
Then it will output the word scanned.
@phrase.downcase.scan(/\w+'?\w+|\w+/)
The above code will scan for a pattern of
1. one or more word character plus an ' (apostrophe)
2. the ? means the pattern to the left is one or none. In this case, whether ' is one or none.
3. follow by another word character of 1or more.
4. If the previous pattern didn't match , then use the second pattern. Which is 1 or more word character
Word character is letters, numbers and underscore
phrase.downcase.scan(/[a-z]+'?[a-z]+|\d+/)
The above code will scan for a pattern of
1. 1 or more any letters
2. 1 or none '
3. follow by 1 or more any letters
4. If the previous pattern didn't match.
5. Then any length of digits.
The above code will scan for a pattern of
1. word boundary
2. 1 or more word character plus '
3. another word boundary
Then it will output the word scanned.
@phrase.downcase.scan(/\w+'?\w+|\w+/)
The above code will scan for a pattern of
1. one or more word character plus an ' (apostrophe)
2. the ? means the pattern to the left is one or none. In this case, whether ' is one or none.
3. follow by another word character of 1or more.
4. If the previous pattern didn't match , then use the second pattern. Which is 1 or more word character
Word character is letters, numbers and underscore
phrase.downcase.scan(/[a-z]+'?[a-z]+|\d+/)
The above code will scan for a pattern of
1. 1 or more any letters
2. 1 or none '
3. follow by 1 or more any letters
4. If the previous pattern didn't match.
5. Then any length of digits.
Comments
Post a Comment