From: "Brian Schröder" Date: 2005-05-30T17:31:23+09:00 Subject: Re: RegExp question On 30/05/05, Jens Riedel wrote: > Hello, > > I need to search a text for a specific pattern, then put all matches > into an array. > Usually I did this while going through the text line by line, but this > time there can be more than one match per line. > > How can I achieve this most simple? > > Example: > > 'This is Example_1 in a line in a long text with Example_2 in the > same line and Example_3 in the next one.' > > Searching for /Example_\d/ should give me an array ("Example_1", > "Example_2", "Example_3") > > Greetings, > Jens > > Hallo Jens, irb(main):001:0> 'This is Example_1 in a line in a long text with Example_2 in the irb(main):002:0' same line and Example_3 in the next one.'.scan(/Example_\d+/m) => ["Example_1", "Example_2", "Example_3"] gr��e, Brian -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/