I am trying to quote arguments that have whitespace or a pipe (vertical
bar character = | ) in them. Why doesn’t this work? What does work?
if arg.index(/[\s|]/)
…
end
I am trying to quote arguments that have whitespace or a pipe (vertical
bar character = | ) in them. Why doesn’t this work? What does work?
if arg.index(/[\s|]/)
…
end
Hi –
On Sat, 29 Jul 2006, Robert La ferla wrote:
I am trying to quote arguments that have whitespace or a pipe (vertical
bar character = | ) in them. Why doesn’t this work? What does work?if arg.index(/[\s|]/)
…end
It seems to work OK:
irb(main):008:0> “abc|”.index(/[\s|]/)
=> 3
irb(main):009:0> " abc".index(/[\s|]/)
=> 0
What results are you getting?
David
On Jul 28, 2006, at 21:56, Robert La ferla wrote:
I am trying to quote arguments that have whitespace or a pipe
(vertical
bar character = | ) in them. Why doesn’t this work? What does work?if arg.index(/[\s|]/)
| is a reserved character in regexes for disjunction, i.e. /a|b/
matches a or b, where a and b are arbitrary regexes.
This ought to work for your purposes, I think:
if arg.index(/[\s|]/)
matthew smillie.
Matthew S. wrote:
| is a reserved character in regexes for disjunction,
Not in a character class.
“foo|bar” =~ /[|]/
=> 3
On 7/28/06, Robert La ferla [email protected] wrote:
I am trying to quote arguments that have whitespace or a pipe (vertical
bar character = | ) in them. Why doesn’t this work? What does work?if arg.index(/[\s|]/)
…end
Seems to work for me:
$ irb
re=/[\s|]/
=> /[\s|]/re.match(‘kldfslkd’)
=> nilre.match(‘df |sdf’)
=> #MatchData:0x4098995c
Regards,
Jason
http://blog.casey-sweat.us/
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs