From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Luis O. Silva" Newsgroups: gmane.emacs.help Subject: Re: a function for string splitting Date: Tue, 26 Nov 2002 22:59:28 +0300 Sender: help-gnu-emacs-admin@gnu.org Message-ID: <15843.53920.300970.277865@localhost.localdomain> References: Reply-To: "Luis O. Silva" NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1038339726 11405 80.91.224.249 (26 Nov 2002 19:42:06 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 26 Nov 2002 19:42:06 +0000 (UTC) Cc: help-gnu-emacs@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18Glar-0002xP-00 for ; Tue, 26 Nov 2002 20:42:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18GlaS-0003hx-00; Tue, 26 Nov 2002 14:41:36 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18GlYy-0002Aj-00 for help-gnu-emacs@gnu.org; Tue, 26 Nov 2002 14:40:04 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18GlYu-00025R-00 for help-gnu-emacs@gnu.org; Tue, 26 Nov 2002 14:40:02 -0500 Original-Received: from relay.wplus.net ([195.131.52.142]) by monty-python.gnu.org with esmtp (Exim 4.10) id 18GlYt-00021i-00 for help-gnu-emacs@gnu.org; Tue, 26 Nov 2002 14:39:59 -0500 X-Real-To: Original-Received: from emaile.wplus.net (emaile.wplus.net [195.131.52.155]) by relay.wplus.net (8.9.1/8.9.1/wplus.2) with ESMTP id WAA89442 for ; Tue, 26 Nov 2002 22:39:57 +0300 (MSK) Original-Received: by emaile.wplus.net with scanned-ok (WebPlus antispam mailer ) id 18GlYq-0003DN-00 for help-gnu-emacs@gnu.org; Tue, 26 Nov 2002 22:39:56 +0300 Original-Received: from [195.131.85.50] (helo=localhost.localdomain) by emaile.wplus.net with esmtp (WebPlus antispam mailer ) id 18GlYp-0003C3-00; Tue, 26 Nov 2002 22:39:55 +0300 Original-To: Lee Sau Dan Original-Newsgroups: gnu.emacs.help In-Reply-To: X-Mailer: VM 6.97 under Emacs 21.1.1 X-Virus-Scanned: by AVP (http://www.avp.ru/) X-IP: 195.131.85.50 X-From: silva@paloma.spbu.ru Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:4058 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:4058 Dear Lee, On 26 Nov 2002 15:49:00 +0100, Lee Sau Dan writes: Luis> My question is what function I could use for Luis> correctly splitting the string. Luis> Please be indulgent with me since Luis> 1. I'm not a programmer 2. I don't have access to the Luis> elisp manual even on-line (my connection is very Luis> slow, only sufficient to download my e-mail). Lee> Consider learning "regular expressions", which are not Lee> only useful in Emacs, but also useful throughout the Lee> unix environment (e.g. grep, sed, awk, vi, ...). Lee> Try: Lee> (let ((date-string "Thu, 21 Nov 2002 16:05:50 -0600") Lee> (regex-fragment-1 "\\([A-Z][a-z]*\\), ") Lee> (regex-fragment-2 "\\([0-9]+\\)\\([A-Z][a-z]*\\)\\([0-9]+\\) ") Lee> (regex-fragment-3 "\\([0-9]+\\):\\([0-9]+\\):\\([0-9]+\\) ") Lee> (regex-fragment-4 "\\([+-][0-9]*\\)" )) Lee> (if (string-match (concat regex-fragment-1 Lee> regex-fragment-2 Lee> regex-fragment-3 Lee> regex-fragment-4) Lee> date-string) Lee> (let ((day-of-week (match-string 1 date-string)) Lee> (day (match-string 2 date-string)) Lee> (month-name (match-string 3 date-string)) Lee> (year (match-string 4 date-string)) Lee> (hour (match-string 5 date-string)) Lee> (minute (match-string 6 date-string)) Lee> (second (match-string 7 date-string)) Lee> (tz-spec (match-string 8 date-string))) Lee> (list day month-name year hour minute second tz-spec)))) Thank you very much. This is just what I needed. I have an incipient notion of regular expressions and I had used them to do search in buffers. I didn't know of the existence of the function `string-match'. Lee> Note that I've broken up the regex into 4 fragments to Lee> make it usenet friendly, rejoining them with (concat Lee> ...). This is not really necessary. Yes, it is not necessary but this nicety will also be useful for me. Thanks a lot. Regards, luis -- Luis Octavio Silva P. St. Petersburg State University. 66/3 Botanicheskaya St., Apt.119/2 Stary Peterhof St. Petersburg, Russia.