简体   繁体   English

Emacs正则表达式搜索然后编写

[英]Emacs regex search then write

I would like to find/extract a group in each line of a buffer, then write it to a new buffer. 我想在缓冲区的每一行中查找/提取一个组,然后将其写入新的缓冲区。

So in my comma-delimted data file, my lines basically look like this: 因此,在逗号分隔的数据文件中,行基本上如下所示:

'A-field','B-field','C-field','D-field'

ie, four single-quoted fields of data per line. 即每行四个单引号的数据字段。 I want to extract the quoted B-field and write it to a new buffer. 我想提取引用的B字段并将其写入新的缓冲区。

Is it possible at the elisp repl to extract from one buffer and write that to a new buffer? elisp repl是否有可能从一个缓冲区中提取并将其写入新缓冲区? Or is this something you'd write as a stand-alone .el file then call from the buffer (M-my-extract-write) from the mini-buffer? 还是这是您要编写为独立的.el文件,然后从迷你缓冲区从缓冲区调用(M-my-extract-write)的东西?

Here's one way to do that: 这是一种方法:

  • copy&paste your file's content to a new buffer. 将文件内容复制并粘贴到新缓冲区中。
  • in the new buffer do Cu Cs ^[^,]*,'\\([^']*\\)',.* M-% \\1 RET ! 在新缓冲区中执行Cu Cs ^[^,]*,'\\([^']*\\)',.* M-% \\1 RET ! .

I recommend multiple-cursors + sexp movements for stuff like this. 对于这种事情,我建议使用多光标 + sexp运动。

Macros also work well, but the immediate feedback of multiple-cursors is nice. 宏也可以很好地工作,但是多光标的即时反馈很好。

Writing elisp to handle simple repetitive tasks is overkill. 编写elisp来处理简单的重复任务实在是太过分了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM