regular expression question

S

seannakasone

is there a way to convert the strings "Outer" to "Inner" and "outer" to
"inner" with one regular expression?
 
P

Phrogz

is there a way to convert the strings "Outer" to "Inner" and "outer" to
"inner" with one regular expression?

irb(main):001:0> str = "There are both Outer and Inner Geebles."
=> "There are both Outer and Inner Geebles."
irb(main):002:0> str.gsub( /Outer|Inner/ ){ |sub| sub.downcase }
=> "There are both outer and inner Geebles."
 
R

Robert Klemme

is there a way to convert the strings "Outer" to "Inner" and "outer" to
"inner" with one regular expression?

irb(main):001:0> repl = {"outer"=>"inner","Outer"=>"Inner"}
=> {"Outer"=>"Inner", "outer"=>"inner"}
irb(main):002:0> "outer Outer".gsub!(/outer/i) {|m| repl[m]}
=> "inner Inner"

Kind regards

robert
 
P

Phrogz

Phrogz said:
irb(main):001:0> str = "There are both Outer and Inner Geebles."
=> "There are both Outer and Inner Geebles."
irb(main):002:0> str.gsub( /Outer|Inner/ ){ |sub| sub.downcase }
=> "There are both outer and inner Geebles."

Oops...I totally misread the question. Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top