From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marc Tfardy Newsgroups: gmane.emacs.help Subject: Re: Problem with regexp nested groups Date: Sun, 11 May 2008 00:31:42 +0200 Message-ID: <68mm2gF2t6ndcU1@mid.individual.net> References: <68lv38F2tabu7U1@mid.individual.net> <87bq3e6ikc.fsf@nonospaz.fatphil.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1210459769 20217 80.91.229.12 (10 May 2008 22:49:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 May 2008 22:49:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 11 00:50:05 2008 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 1JuxtC-0005YN-Sx for geh-help-gnu-emacs@m.gmane.org; Sun, 11 May 2008 00:50:03 +0200 Original-Received: from localhost ([127.0.0.1]:45597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JuxsU-0003Pm-EF for geh-help-gnu-emacs@m.gmane.org; Sat, 10 May 2008 18:49:18 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-X-Trace: individual.net pr5d0nMrHl0i3sYSU/2nrAxMv2M0XnPgl4CavfYZ0VxVip5xXg Cancel-Lock: sha1:hnKXKhCNp02vbCT5jmB4oM5bENA= User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) In-Reply-To: <87bq3e6ikc.fsf@nonospaz.fatphil.org> Original-Xref: news.stanford.edu gnu.emacs.help:158528 X-Mailman-Approved-At: Sat, 10 May 2008 18:48:09 -0400 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:53896 Archived-At: Phil Carmody schrieb: > Marc Tfardy writes: >> Hallo, >> >> I have some problem with regexp and I hope someone could help me. >> >> >> Assume we have following text in a buffer. >> >> -- DATA ---------------------------------------------------------------- >> >> >> blablalba >> >> blabla >> OBJ('some/file/sample4.mp3') >> OBJ('some/file/sample5.au') >> ------------------------------------------------------------------------ >> >> My goal is to extract some text from the buffer, namely only >> portion of text between `DATA="' and `"' or between `OBJ('' and >> `''. In both cases text must end with `.mp3' and the left and >> right delimeter shoud be ignored. > ... >> "\\(DATA=\"\\(.*?\.mp3\\)\"\\|OBJ('\\(.*?\.mp3\\)')\\)" nil t) > > How about grouping /DATA="/ or /OBJ('/ as match 1, then capture > the filename as 2, and end with /.mp3"/ or /.mp3'/ as match 3? Interesting idea and it really works and it is definitely better then multiple (match-string-no-properties x). I've modified slightly your suggestion and I put extension togother with filename: "\\(DATA=\"\\|OBJ('\\)\\(.*?\.mp3\\)\\(\"\\|')\\)" So I need only to refer (match-string-no-properties 2). > That would match malformed lines such as > > DATA="foo.mp3' > > but if that's a problem you can capture the quotes too and > fix them in post-production. This disadvantage I can get over. The really problem occur when the extract part of text exist not at position 2 (in case of another, more complicated regexp). In this case I have the same type of problem like in my first posting. regards Marc