all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Politz <politza@fh-trier.de>
To: help-gnu-emacs@gnu.org
Subject: Re: Help with regexp
Date: Wed, 02 Dec 2009 14:31:21 +0100	[thread overview]
Message-ID: <87ocmhtsd2.fsf@fh-trier.de> (raw)
In-Reply-To: 87vdgpbtlp.fsf@ergodik.univ-brest.fr

harven <harven@free.fr> writes:

> Andreas Politz <politza@fh-trier.de> 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





  reply	other threads:[~2009-12-02 13:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.11978.1259698881.2239.help-gnu-emacs@gnu.org>
2009-12-01 21:07 ` Help with regexp Pascal J. Bourguignon
2009-12-02  5:16   ` tomas
2009-12-02  6:03     ` Andreas Politz
2009-12-02  7:11       ` tomas
2009-12-02  8:14         ` Andreas Politz
2009-12-05  6:46           ` tomas
2009-12-02  7:18       ` suvayu ali
     [not found]     ` <mailman.12000.1259733814.2239.help-gnu-emacs@gnu.org>
2009-12-02  9:41       ` harven
2009-12-02 13:31         ` Andreas Politz [this message]
2009-12-02 16:05           ` Lennart Borgman
2009-12-02 16:56             ` Andreas Politz
2009-12-02 17:16               ` Lennart Borgman
     [not found]               ` <mailman.12039.1259774199.2239.help-gnu-emacs@gnu.org>
2009-12-02 20:00                 ` harven
2009-12-02 17:01           ` Andreas Politz
     [not found]         ` <mailman.12029.1259760724.2239.help-gnu-emacs@gnu.org>
2009-12-02 14:16           ` Pascal J. Bourguignon
2009-12-02  6:36   ` Xavier Maillard
     [not found]   ` <mailman.12002.1259735748.2239.help-gnu-emacs@gnu.org>
2009-12-02 11:16     ` Pascal J. Bourguignon
     [not found]   ` <mailman.11999.1259731365.2239.help-gnu-emacs@gnu.org>
2009-12-03  3:48     ` Stefan Monnier
2009-12-02 15:37 ` Colin S. Miller
2009-12-01 20:21 Xavier Maillard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ocmhtsd2.fsf@fh-trier.de \
    --to=politza@fh-trier.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.