Regex to match string excluding first character
gsub, regex, ruby, string
Solution
You can simply capture the character before the slash in a group and use that in the replacement, for example:
"/hello/world".gsub(/([^\/])\//, '\1%2F') #=> "/hello%2Fworld"
Or if you just want to match any `/` that appears after the first character, you can simplify this to:
"/hello/world".gsub(/(.)\//, '\1%2F') #=> "/hello%2Fworld"
Or like this:
"/hello/world".gsub(/(?<!^)\//, '%2F') #=> "/hello%2Fworld"
Problem
I'm writing ruby and need some help with regex. And I'm really noob in regexp. I have a string like this ``` /hello/world ``` I would like to #gsub this string to change the second slash to %2F. The challange for me to ignore the first slash and to change only the second slash. I tried this one ``` [^/]/ ``` but it chooses not clean slash but o/ in ``` /hello/world ``` Please, help me. Thanks!!