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

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

Re: Problem with regexp nested groups


From: Lennart Borgman (gmail)
Subject: Re: Problem with regexp nested groups
Date: Sat, 10 May 2008 21:32:33 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

Marc Tfardy wrote:
Hallo,

I have some problem with regexp and I hope someone could help me.


Assume we have following text in a buffer.

-- DATA ----------------------------------------------------------------
<DATA="some/file/sample1.mp3">
<DATA="some/file/sample2.mp3">
blablalba
<DATA="some/file/sample3.wav">
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. So the right result should look
like this:

some/file/sample1.mp3
some/file/sample2.mp3
some/file/sample4.mp3


I wrote this test function:

(defun get-data ()
  (interactive)
(if (re-search-forward "\\(DATA=\"\\(.*?\.mp3\\)\"\\|OBJ('\\(.*?\.mp3\\)')\\)" nil t)
      (message "found: %s" (match-string-no-properties 1))
    (message "failed")))

With (match-string-no-properties 1) I get this result:

found: DATA="some/file/sample1.mp3"
found: DATA="some/file/sample2.mp3"
found: OBJ('some/file/sample4.mp3')

Not good. Now I replace (match-string-no-properties 1) with
(match-string-no-properties 2) and I get only two results for
both DATA lines:

found: some/file/sample1.mp3
found: some/file/sample2.mp3
found: nil

The version with (match-string-no-properties 3) returns
only OBJ line:

found: some/file/sample4.mp3
found: nil


Now the final question: how can I get results like version 2 and
3 but at ones? I would be grateful for any help

regards

Marc

Could you perhaps look for both (match-string-no-properties 1) and dito 2?




reply via email to

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