P
Phlip
Rubies:
Someone didn't escape their & in their HTML correctly. Let's fix it.
This regexp correctly does not escape &dude, because we only want to escape
raw & markers:
p "yo &dude".gsub(/&([^a-z])/i, '&\1')
That passed "yo &dude" thru unchanged. (I am aware "dude" has no ; on the
end; we are leaving that optional, for whatever reason...)
Now escape & followed by a non-alphabetic character:
p "yo & dude".gsub(/&([^a-z])/i, '&\1')
That correctly provides: "yo & dude"
Now how to escape "yo && dude"? Note that the ([^a-z]) consumes the second
&, leading to this incorrect output:
"yo && dude"
The only workaround I can think of is to run the Regexp twice:
x = "yo && dude"
2.times{ x.gsub!(/&([^a-z])/i, '&\1') }
p x
Can someone help my feeb Regexp skills and get a "yo && dude" in one
line?
Someone didn't escape their & in their HTML correctly. Let's fix it.
This regexp correctly does not escape &dude, because we only want to escape
raw & markers:
p "yo &dude".gsub(/&([^a-z])/i, '&\1')
That passed "yo &dude" thru unchanged. (I am aware "dude" has no ; on the
end; we are leaving that optional, for whatever reason...)
Now escape & followed by a non-alphabetic character:
p "yo & dude".gsub(/&([^a-z])/i, '&\1')
That correctly provides: "yo & dude"
Now how to escape "yo && dude"? Note that the ([^a-z]) consumes the second
&, leading to this incorrect output:
"yo && dude"
The only workaround I can think of is to run the Regexp twice:
x = "yo && dude"
2.times{ x.gsub!(/&([^a-z])/i, '&\1') }
p x
Can someone help my feeb Regexp skills and get a "yo && dude" in one
line?