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

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

Re: Help with regexp


From: harven
Subject: Re: Help with regexp
Date: Wed, 02 Dec 2009 10:41:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

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

??

\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




reply via email to

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