From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: harven Newsgroups: gmane.emacs.help Subject: Re: Help with regexp Date: Wed, 02 Dec 2009 10:41:53 +0100 Organization: http://groups.google.com Message-ID: <87vdgpbtlp.fsf@ergodik.univ-brest.fr> References: <87y6lmtnbx.fsf@galatea.local> <20091202051626.GA19970@tomas> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259750503 8016 80.91.229.12 (2 Dec 2009 10:41:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Dec 2009 10:41:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 02 11:41:37 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NFmeO-0001Xy-NP for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Dec 2009 11:41:36 +0100 Original-Received: from localhost ([127.0.0.1]:37518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFmeO-0008Im-4Z for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Dec 2009 05:41:36 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!proxad.net!feeder1-2.proxad.net!u-picardie.fr!utc.fr!news.univ-lille1.fr!crihan.fr!news.univ-brest.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 48 Original-NNTP-Posting-Host: mathw171.univ-brest.fr Original-X-Trace: news.univ-brest.fr 1259747038 23339 172.19.130.171 (2 Dec 2009 09:43:58 GMT) Original-X-Complaints-To: usenet@news.univ-brest.fr Original-NNTP-Posting-Date: 2 Dec 2009 09:43:58 GMT User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:orZE/HmroO/xovQ5weGsRngZJ5Q= Original-Xref: news.stanford.edu gnu.emacs.help:175237 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:70312 Archived-At: Andreas Politz writes: > Things I (won't) miss most: > > - extreme backslasheritis > - no short aliases for important constructs : > digits,symbol-constituents,newline,space ?? \sw word constituent. Same as \w. \s_ symbol constituent. \s- whitespace character. Same as [[:space:]] See the wiki for the full list http://www.emacswiki.org/emacs-en/RegularExpression In a string you can use \n to match a newline, \t to match a tab. That's the reason why you have to use \\ to match a backslash. You can of course define your own classes using the category mechanism. And there is a user-friendly syntax with the rx command. Finally, if you miss perl, just use it. The following command will search, replace with the perl engine. (defun my-perl (prefix start end code) "ask for a perl expression in the minibuffer. Execute with the region as input. By default, the result is put in a separate buffer. If an argument is given, replace the region with the output. The perl command is executed with the -ln switches." (interactive "P\nr\nsPerl : ") (shell-command-on-region start end (concat "perl -lne '" code "'") (if prefix '(nil t)))) Examples List lines in the region that contain the string "string" M-x my-perl RET print if /string/ RET Replace in the region all e by E C-u M-x my-perl RET s/e/E/g;print RET Count the number of lines in the region M-x my-perl RET print $. if eof RET