Re: Regular expression



2009/5/29 Harry Kakueki <list.push@xxxxxxxxx>:
On Fri, May 29, 2009 at 5:48 PM, Brian Candler <b.candler@xxxxxxxxx> wrote:

I think you need a negative lookahead assertion.
* http://www.ruby-doc.org/docs/ProgrammingRuby/
* click on "The Ruby Language"
* scroll to "Extensions"
* look for (?!re)

irb(main):009:0> /^(.)(?!\1)(.)(?!\1|\2)(.)(\2)$/ =~ "abcb"
=> 0
irb(main):010:0> /^(.)(?!\1)(.)(?!\1|\2)(.)(\2)$/ =~ "abbb"
=> nil

I need to read that section carefully to be sure I understand.
But, I think that does the trick.

The problem with this approach is that it does not work for strings of
arbitrary length. Even if you adjust it to work for multiple lengths
you always have a fixed upper limit for which it can work.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

.



Relevant Pages

  • Re: Most compact command for associate array totalling?
    ... On Aug 7, 2008, at 5:27 PM, Siep Korteling wrote: ... But I"m sure there is a shorter way? ... Better trick available here? ... As an aside to 'to_i' is to turn the 'nil' into zero: ...
    (comp.lang.ruby)
  • Re: Encarta 2007
    ... Sound fragmnets only seems not to work. ... Perhaps the extensions are not ... This is a .NET programming group. ... open and scroll down to "Encarta Discussions" and post there. ...
    (microsoft.public.dotnet.general)
  • Re: reconfigure php4-extensions
    ... >> Now I want to install some extensions that I didn't choose the first time ... I'm not sure what did the trick in the end, but some combined effect of the ... make install (compiled the new extension, then asked for a deinstall) ...
    (freebsd-questions)
  • Re: Mouse wierdness! Anyone experienced this?
    ... The VBScroll program did the trick ... For some reason, the mouse points and clicks fine... ... scroll device doesn't work with VB6 development environment on this ... It's a standard Microsoft Wheel mouse, ...
    (microsoft.public.vb.general.discussion)
  • Disable Mouse Scroll Down
    ... master. ... He has a mouse program there that may do the trick. ... >name, and system time. ... >disable the Mouse Scroll down key, it still can go to the ...
    (microsoft.public.access.forms)