From: "Jesús Gabriel y Galán" Date: 2008-12-05T03:10:43+09:00 Subject: Re: reg exp On Thu, Dec 4, 2008 at 3:34 AM, Hai anh Le wrote: > I have a problem with regexp. I have some document like : > > A method for detecting a post-translationally modified protein with a > glycosyl group comprising contacting the protein with a glycosyl > transferase enzyme and a labeling agent, wherein the labeling agent > comprises a chemical handle and a transferable glycosyl group. > > I want to divide it to some string follow a rule that string start with > "a, an, the" like : > > "A method for detecting " > "a post-translationally modified protein with " > "a glycosyl group comprising contacting " > "the protein with " > "a glycosyl transferase enzyme and " > "a labeling agent, wherein " > "the labeling agent comprises " > "a chemical handle and " > "a transferable glycosyl group." I though of split, but then you get an array entry for the "separator" and the following part, so you would need to paste them again yourself: irb(main):008:0> a = "A method for detecting a post-translationally modified protein with a glycosyl group comprising contacting the protein with a glycosyl transferase enzyme and a labeling agent, wherein the labeling agent comprises a chemical handle and a transferable glycosyl group." => "A method for detecting a post-translationally modified protein with a glycosyl group comprising contacting the protein with a glycosyl transferase enzyme and a labeling agent, wherein the labeling agent comprises a chemical handle and a transferable glycosyl group." irb(main):011:0> require 'enumerator' => true irb(main):012:0> result = [] => [] irb(main):015:0> a.split(/\b(a|an|the)\b/i)[1..-1].each_slice(2) {|a, b| result << (a+b)} => nil irb(main):016:0> result => ["A method for detecting ", "a post-translationally modified protein with ", "a glycosyl group comprising contacting ", "the protein with ", "a glycosyl transferase enzyme and ", "a labeling agent, wherein ", "the labeling agent comprises ", "a chemical handle and ", "a transferable glycosyl group."] Maybe someone can come with a split solution easier to join? Hope this helps, Jesus.