[Top][All Lists]

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

Re: Help with regexp

From: Pascal J. Bourguignon
Subject: Re: Help with regexp
Date: Wed, 02 Dec 2009 15:16:49 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Andreas Politz <address@hidden> writes:

> harven <address@hidden> writes:
>> Andreas Politz <address@hidden> 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
>> 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...

Of course you can:

(defun test (string)
  (interactive "sPlease enter a string: ")
  (insert string))

>> Count the number of lines in the region
>> M-x my-perl RET print $. if eof RET
> That maybe a good workaround, thanks.

It would be nicer to just implement the new regexp syntax in emacs
lisp, translating to the old regexp syntax.

> 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.

But in any case, it would be better to use sexps to build regexps:

(seq "=>" (rep (comp ":"))
          (alt ""
               (seq ":" (rep (comp ":"))
                    (alt ""
                         (seq ":" (rep (comp ":"))
                              (alt ""
                                   (seq ":" (rep (comp ":")))))))))


(defun seq (&rest seq) (apply (function concat) seq))
(defun rep (&rest seq) (format "\\(%s\\)*" (apply (function concat) seq)))
(defun alt (alt &rest rest) 
      (princ "\\(")
      (princ alt)
      (dolist (alt rest)
         (princ "\\|")
         (princ alt))
      (princ "\\)")))
(defun comp (&rest chars)  (format "[^%s]" (apply (function concat) chars)))

__Pascal Bourguignon__

reply via email to

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