J
Jim Freeze
Hi:
I am looking for a regex that will match a line with a single
carrot:
line = "^\n"
However, the obvious does not seem to work:
irb(main):001:0> line1 = "^\n"
=> "^\n"
irb(main):002:0> line2 = "fred"
=> "fred"
irb(main):003:0> /^^/ =~ line1
=> 0
irb(main):004:0> /^^/ =~ line2
=> 0
Using /^\^/ gives an error.
What I have done to temporarily solve the problem is to use:
irb(main):012:0> /^[ ^]/ =~ line1.strip
=> 0
irb(main):011:0> /^[ ^]/ =~ line2.strip
=> nil
Does anyone know how to match '^' at the beginning of a line?
I am looking for a regex that will match a line with a single
carrot:
line = "^\n"
However, the obvious does not seem to work:
irb(main):001:0> line1 = "^\n"
=> "^\n"
irb(main):002:0> line2 = "fred"
=> "fred"
irb(main):003:0> /^^/ =~ line1
=> 0
irb(main):004:0> /^^/ =~ line2
=> 0
Using /^\^/ gives an error.
What I have done to temporarily solve the problem is to use:
irb(main):012:0> /^[ ^]/ =~ line1.strip
=> 0
irb(main):011:0> /^[ ^]/ =~ line2.strip
=> nil
Does anyone know how to match '^' at the beginning of a line?