[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 <xma@gnu.org> 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 !@#$^^& also"
;; no match:
"=>:::" "=>a:b:c:d"))
--> (0 0 0 0 0 0 0 0 nil nil)
--
__Pascal Bourguignon__
- Help with regexp, Xavier Maillard, 2009/12/01
- Message not available
- Re: Help with regexp, harven, 2009/12/02
- Re: Help with regexp, Andreas Politz, 2009/12/02
- Re: Help with regexp, Lennart Borgman, 2009/12/02
- Re: Help with regexp, Andreas Politz, 2009/12/02