I am trying to write a script that will match all words in a string and will strip all non words (IE: . [dot], ampersands, colons, etc) out and will replace them with a hyphen.
Example String:
L. L. Cool J & Sons: The Cool Kats
Example Output:
L-L-Cool-J-Sons-The-Cool-Kats
Here is some code I am working with:
str = "L. L. Cool J & Sons: The Cool Kats"
str.scan(/\w+/)
Thanks for all the help! I am still pretty new to regex
Update: I just noticed that the two calls can be expressed as one:
…which results to the same as Narendra’s answer or my original answer: