ruby - Why is gsub not working whenever GT sign ">" is the first character in regex -


in text data working on greather sign supposed final character. hence, wanted replace non-conforming occurences that:

some_variable.gsub!(/>([^\n])/, ">\n\\1") 

however, keep getting *undefined method gsub!' nil:nilclass (nomethoderror)* error when calling thisgsub!` – if escape character backslash. surprise, changing gt sign not first 1 in regex:

some_variable.gsub!(/(.)>([^\n])/,"\\1\n\\2") 

makes work. why? isn't weird gsub return nil?

this has nothing gsub!. error message says try call gsub! on nil, i.e. means some_variable nil when don't expect be. argument gsub!, call gsub! itself, irrelevant, problem some_variable nil when expect string.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -