I have trouble with converting the following line from PHP to Ruby:
strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), trim($str)));
Is it possible to accomplish this in one line just like in here?
I have trouble with converting the following line from PHP to Ruby:
strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), trim($str)));
Is it possible to accomplish this in one line just like in here?
str.strip.gsub(/[^a-zA-Z0-9 -]/, '').gsub(/[ -]+/, '-').gsub(/^-|-$/, '').downcase
could be further simplified to:
str.strip.gsub(/[ -]+/, '-').gsub(/[^a-z \d-]|^-|-$/i, '').downcase