Hihi,
I have 2 problems.
--------------Question 1-----------------------
Firstly, a Ruby question. I'm confused about how to match a single
regular expression multiple times in a single string. For instance,
'llgllallo'.match(/(ll.)/)[0] #-> 'llg'
'llgllallo'.match(/(ll.)/)[1] #-> 'llg'
'llgllallo'.match(/(ll.)/)[1] #-> nil
How do I access all 3 matches? String#scan will work, but that gives me
'llgllallo'.scan(/(ll.)/) #=> [["llg"], ["lla"], ["llo"]]
But I need the offsets, and this info isn't given to me.
--------------Question 2-----------------------
Now an old gap in my regex understanding. How do I exclude on
consecutive characters? I want something like [^abc], except aba or bbc
is ok, just not 'abc'. Summing this up:
reg = /something/
'abc'.match(reg) #-> no match
'cba'.match(reg) #-> match
And then I want to be able to do OR operations too, like not 'abc' and
not 'bbc', but that is probably another step of complexity.
I don't suppose there is any way to pass a block to the regex to use in
a specific place? That would be cool, though maybe not possible given
optimisations in regex?
Thanks in advance,
ben
···
--
Posted via http://www.ruby-forum.com/.