Re: How to find multiple matches in a string
- From: Robert Klemme <shortcutter@xxxxxxxxxxxxxx>
- Date: Wed, 14 Apr 2010 07:42:13 +0200
On 13.04.2010 19:01, Alex DeCaria wrote:
Andrea Dallera wrote:Hei,
s = 'abcde_abcde_abcde'
m = s.scan(/b/)
p m # ['b','b','b']
Thanks Andrea. But is there a way to also find the locations (indexes)
of the 'b' characters?
irb(main):012:0> s="a "*5
=> "a a a a a "
irb(main):013:0> s.scan(/a+/) { p $~, $~.offset(0) }
#<MatchData "a">
[0, 1]
#<MatchData "a">
[2, 3]
#<MatchData "a">
[4, 5]
#<MatchData "a">
[6, 7]
#<MatchData "a">
[8, 9]
=> "a a a a a "
irb(main):014:0>
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
.
- References:
- How to find multiple matches in a string
- From: Alex DeCaria
- Re: How to find multiple matches in a string
- From: Andrea Dallera
- Re: How to find multiple matches in a string
- From: Alex DeCaria
- How to find multiple matches in a string
- Prev by Date: Re: how to delete the first two characters of each row?
- Next by Date: Re: i don't know:&:empty?
- Previous by thread: Re: How to find multiple matches in a string
- Next by thread: Re: How to find multiple matches in a string
- Index(es):
Relevant Pages
|