开发者

Emacs Searching

开发者 https://www.devze.com 2023-02-25 15:53 出处:网络
I have a convoluted search request. Lets say that I am searching for an URI pattern. I do know the scheme and the authority. Lets say http://mycompany.com.

I have a convoluted search request. Lets say that I am searching for an URI pattern. I do know the scheme and the authority. Lets say http://mycompany.com.

After this URI pattern, ideally most of the URI in my search domain have two path variable. /Context/Resource. Although it could have more. But it will always have a context.

I would like to find the distinct set of first path variable. I do not mind about the second and subsequent path variable.So if I have this.Lets u开发者_开发知识库se a qname is myc.

    myc:/context1/resource1
    myc:/context1/resource2
    myc:/context2/resource1
    myc:/context3/resource1
    myc:/context4/resource8
    myc:/context1/resource12

I will have to get context1..4. Thank You for your time.


If I understand you correctly,

(require 'cl)

(remove-duplicates
 (loop while (re-search-forward "myc:/\\(.*?\\)/" nil t)
       collect (match-string-no-properties 1))
 :test #'string=)


Emacs supports regex searches which are normally bound to C-M-s. The Emacs manual has a nice section about regular expressions in Emacs.

There is also M-x regexp-builder to help you build the search string with real-time feedback.

0

精彩评论

暂无评论...
验证码 换一张
取 消