From: Dylan Date: 2009-09-03T01:50:15+09:00 Subject: Re: Reg Ex exclusion On Sep 2, 9:17 am, Ne Scripter wrote: > Hi all, > > I thought this would be easy, but I am clearly mixing up my logic. I > have a string like so > > string = "joe|blogg|clothing|" > > I want to remove the last pipe with a reg ex and I am trying to use the > following code to do so: > > string(/\|$/, 1) > > This however is not doing anything except delete the entire string, any > suggestion are greatly appreciated. > > Many thanks > -- > Posted viahttp://www.ruby-forum.com/. Are you actually getting results from "string(/\|$/,1)"? I get what I would expect: irb(main):001:0> st="joe|blogg|clothing|" => "joe|blogg|clothing|" irb(main):004:0> st(/(.*)\|$/) #: undefined method `st' for main:Object I think you mean [ ] Try this: string[/(.*)\|$/,1] irb(main):010:0> st[/(.*)\|$/,1] => "joe|blogg|clothing" By the way, if you're doing this to split up that string into joe, blogg and clothing later, you can just skip the Regex and use split: irb(main):011:0> st.split("|") => ["joe", "blogg", "clothing"] -Dylan