help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with regexp


From: Andreas Politz
Subject: Re: Help with regexp
Date: Wed, 02 Dec 2009 14:31:21 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]