I'll have a go at explaining, although I'm no expert on Regexp.

str.scan(/(\w+)[[:punct:]]/).flatten

"str" - Take the String object

".scan(" - Execute the method "scan" which is available to String.

"/" - Regexp shorthand. A Regular Expression matches a pattern using 
special characters.

"(\w+)" - The parentheses indicate a "capture" group. This means that 
you can match a specific subsection of the pattern and extract it. The 
"\w" means any character in a word, like a letter, number, or 
underscore. The "+" means 1 or more.

"[[:punct:]]" - means match punctuation. According to a quick Googling 
this is "-[]\;',./!@#%&*()_{}::"?" Because this is outside the capture 
group it is excluded.

"/" - Closes the Regexp.

")" - Closes the "scan" argument.

".flatten" - Turns the nested Array returned by using scan with captures 
into a simple Array.

____________________________
str.scan(/\w+(?=[[:punct:]])/)

The difference with this one is that "(?=" excludes the punctuation from 
the output.

According to this:
http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm

(?= re)  Specifies position using a pattern. Doesn't have a range.

-- 
Posted via http://www.ruby-forum.com/.