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

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -