From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Help with regexp Date: Wed, 02 Dec 2009 15:16:49 +0100 Organization: Informatimago Message-ID: <87ljhlmpf2.fsf@galatea.local> 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 1259775305 30945 80.91.229.12 (2 Dec 2009 17:35:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Dec 2009 17:35:05 +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 18:34:58 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 1NFt2m-00026T-MV for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Dec 2009 18:31:12 +0100 Original-Received: from localhost ([127.0.0.1]:59376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NFt2m-0007wr-AQ for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Dec 2009 12:31:12 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 83 Original-X-Trace: individual.net WuJHgUvgclIiWWXUAab1YgUpvy46EbX9w+RoLZdRlvb08f5lvl Cancel-Lock: sha1:YzExMTE1MTE5ZmQxM2FmNDgyMzJiYzIyYzRhOWYyZjY0MWRjOTBjYg== sha1:Z2b3IUji+DTqe+icLCzMSG3HDt8= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:175250 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:70325 Archived-At: Andreas Politz writes: > 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... 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) (with-output-to-string (princ "\\(") (princ alt) (dolist (alt rest) (princ "\\|") (princ alt)) (princ "\\)"))) (defun comp (&rest chars) (format "[^%s]" (apply (function concat) chars))) -- __Pascal Bourguignon__