1. Remove any non a-z, numbers, etc completely before sticking in the underscores?
Code:
'1. hello ($$$) world'.gsub(/[^\w ]+/, '')
=> "1 hello world"
The ^ means match anything not between the square brackets (letters, numbers, space).
2. Remove any double/triple/etc. instances of underscores? What sometimes happens is the it turns out as NAME____blah__asdf, i'd like to shrink that down to just one underscore?
Code:
'This is only a test.'.gsub(/\W+/, '_')
=> "This_is_only_a_test_"
The + means match one or more of the previous character.
Bookmarks