On Oct 28, 10:12 ¨Âí¬ ÁìÄó ¼áìåøä®®®Àçíáéì®ãïí¾ ÷òïôåº
> I have to capture by means of regexp the content between '<' and '>'
>
> as instance:
>
> str = 'anystring<hour>anystring<min>anystring<sec>anystring'
> I need the array['hour','min,'sec']
>
> I have written the regexp: /(<([^<>]+)>)+/
> and I have tested it in rubular.com site (It work !)
>
> I have run it in irb:>> /(<([^<>]+)>)+/.match('anystring<hour>anystring<min>anystring<sec>anystring')
>
> => #<MatchData "<hour>" 1:"<hour>" 2:"hour">
>
> As you can see match method return just the first match in MatchData obj
>
> Do you know why ?
>
> thank you,
> Alessandro
> --
> Posted viahttp://www.ruby-forum.com/.

Alessandro,

You'll want the String#scan method (http://www.ruby-doc.org/core/
classes/String.html#M000812).

  015:0> regexp = /<([^<>]+)>/
  => /<([^<>]+)>/
  016:0> str = 'anystring<hour>anystring<min>anystring<sec>anystring'
  => "anystring<hour>anystring<min>anystring<sec>anystring"
  017:0> str.scan(regexp)
  => [["hour"], ["min"], ["sec"]]

HTH,
Chris