help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with regexp


From: Pascal J. Bourguignon
Subject: Re: Help with regexp
Date: Tue, 01 Dec 2009 22:07:46 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Xavier Maillard <address@hidden> writes:

> Hi,
>
> I am trying to find the regexp that could match on these:
>
> "=>foo"
> "=>foo:bar"
> "=>foo:bar:baz"
>
> The regexp must match on all of these strings. The string can't
> be deeper than 3 levels (like latest example) and each component
> may have spaces.
>
> How can I match this ?

"=>\\([^:]*\\(\\|:[^:]*\\(\\|:[^:]*\\)\\)\\)"

Accepts also "=>::".  Replace the stars with \\+ if you want to have
at least one character between the colons.

(mapcar (lambda (s)
         (string-match "^=>\\([^:]*\\(\\|:[^:]*\\(\\|:[^:]*\\)\\)\\)$" s))
        '("=>foo"
          "=>foo:bar"
          "=>foo:bar:baz"
          "=>" "=>:" "=>::" 
          "=>This is : also a good : example"
          "=>And this one address@hidden& also"
          ;; no match:
          "=>:::" "=>a:b:c:d"))
--> (0 0 0 0 0 0 0 0 nil nil)


-- 
__Pascal Bourguignon__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]