I am trying to make a snippet that takes the selected text and puts it into a tag ID. I can do it with a single word, but if the selection contains multiple words, I was to replace the spaces in the selection with hyphens before inserting as the ID. This is not working:

I'm rusty with my regex but I'm guessing that it would be an easier fix in Perl or some other scripting language. In Ruby, you could just use the downcase method. Foo-Bar.downcase would render "foo-bar"

([a-zA-Z]+) captures one or more letters into group 1, provided they are also followed by space(s) or a word-break.(?:(\s+?)|\b) is a non-capturing group, but if there are one or more spaces these are captured into a group, 2.

The ? following \s+ is necessary to create a non-greedy capture, otherwise the 'g' modifier will possibly force a capture of the whole line in one go!

?1: is a conditional, which says 'if anything was captured in group 1', insert this..(?2:-) is a nested-conditional, and it will be ignored if there was no capture for group 2.