RegExp question

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

···

On 30/05/05, Jens Riedel <JensRie@gmx.de> 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

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Hallo Brian,

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"]

vielen Dank, scan() hatte ich noch gar nicht entdeckt.

Grüße,
Jens