From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Help with regexp Date: Wed, 02 Dec 2009 14:31:21 +0100 Message-ID: <87ocmhtsd2.fsf@fh-trier.de> References: <87y6lmtnbx.fsf@galatea.local> <20091202051626.GA19970@tomas> <87vdgpbtlp.fsf@ergodik.univ-brest.fr> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1259769557 10122 80.91.229.12 (2 Dec 2009 15:59:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Dec 2009 15:59:17 +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 16:59:10 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 1NFrbg-0005Yg-7h for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Dec 2009 16:59:08 +0100 Original-Received: from localhost ([127.0.0.1]:53402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFrbg-0007eU-2r for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Dec 2009 10:59:08 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NFpJK-00012w-KQ for help-gnu-emacs@gnu.org; Wed, 02 Dec 2009 08:32:02 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NFpJF-0000yq-7N for help-gnu-emacs@gnu.org; Wed, 02 Dec 2009 08:32:01 -0500 Original-Received: from [199.232.76.173] (port=54261 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFpJE-0000yc-RP for help-gnu-emacs@gnu.org; Wed, 02 Dec 2009 08:31:56 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:57669) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NFpJE-0002vT-EO for help-gnu-emacs@gnu.org; Wed, 02 Dec 2009 08:31:56 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1NFpJ3-0005W9-Az for help-gnu-emacs@gnu.org; Wed, 02 Dec 2009 14:31:45 +0100 Original-Received: from dslb-084-059-204-226.pools.arcor-ip.net ([84.59.204.226]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 02 Dec 2009 14:31:45 +0100 Original-Received: from politza by dslb-084-059-204-226.pools.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 02 Dec 2009 14:31:45 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 65 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: dslb-084-059-204-226.pools.arcor-ip.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qn8SVc0JZmRkmhuCHKGjNTw9WBc= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:70321 Archived-At: harven writes: > Andreas Politz writes: > > >> Things I (won't) miss most: >> >> - extreme backslasheritis >> - no short aliases for important constructs : >> digits,symbol-constituents,newline,space > > ?? I should have defined short as a synonym for a 2-character sequence. The main idea here is conciseness. > > \sw word constituent. Same as \w. > \s_ symbol constituent. I guess I was involved with vim for a to long time, where \w matches chars in a c identifier, my bad. > \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. > But I can't enter a constant string in the mini-buffer... > 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 That maybe a good workaround, thanks. I guess my main complain would be the over-expressiveness. Be it in the actual regexp, due to backslashes and most atoms being 3-5 characters in length. Or in the replacement, due to missing zero-width matches. -ap