Regex to match any character except a backslash

regex, ruby

Solution

Your problem is not with your regex; you got that right. Your problem is that your test string does not have a backslash in it. It has an escaped space, instead. Try this:

str = "'some string \\ hello'"
puts str                 #=> 'some string \ hello'
p /'[^\\]*'/.match(str)  #=> nil

Problem

How can i say "all symbols except backslash" in Ruby character class? ``` /'[^\]*'/.match("'some string \ hello'") => should be nil ``` Variant with two backslashed doesn't work ``` /'[^\\]*'/.match("'some string \ hello'") => 'some string \ hello' BUT should be nil ```

Original source