TextMate 将正则表达式搜索结果保存到新窗口中
我希望能够在 TextMate 中执行搜索,但将结果匹配复制到单独的文件中。
我使用以下表达式:
(?<=\()(.*?)(?=\))
来匹配嵌入在文本行括号内的电子邮件地址,所以有些东西例如:
AN 其他 ([电子邮件受保护])
我正在处理的文件有几百个条目,所有条目均以 CR-LF (\n) 分隔。
我希望能够仅将文本的电子邮件段提取到新文件中以供进一步处理。但是,TextMate 中的搜索对话框似乎仅支持替换匹配的文本。我只是想知道是否有某种方法可以实现这一点。
I'd like to be able to perform a search within TextMate, but copy the resulting matches into a separate file.
I'm using the following expression:
(?<=\()(.*?)(?=\))
to match an email address embedded within brackets of a line of text, so something like:
A N Other ([email protected])
The file I'm working from has a few hundred entries, all separated by CR-LF (\n).
I'd like to be able to extract only the email segment of the text, into a new file for further processing. However, the search dialog within TextMate only seems to support replacing matched text. I was just wondering if there was some way to accomplish this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是非常旧的,但您可以在 TextMate2 中执行以下操作:
http://manual.textmate.org/searching.html#search-results
This is super old, but you can do the following in TextMate2:
http://manual.textmate.org/searching.html#search-results
命令
Bundles >正文>过滤>将匹配行复制到新文档中
可能是一个很好的起点。不过,您必须匹配整行,因此构造一个正则表达式来容纳(尽管丢弃)您要提取的实际文本之前和之后的任何内容。The command
Bundles > Text > Filtering > Copy Matching Lines into New Document
could be a good starting point. You will have to match full lines though, so construct a regexp to accomodate (although discard) anything before and after the actual text you want to extract.据我所知,TextMate无法实现您想要实现的目标。但是,正如您已经提到的,您想要处理您的文件,即您应该编写一个简单的脚本来执行此操作。
如果您需要经常解析此类文件,则可能值得为 TextMate 编写一个命令(捆绑包 > 捆绑包编辑器 > 显示捆绑包编辑器 > 新命令)。
如果这是一次性活动,您可能最好从命令行执行所有操作,即使用 grep、sed 和 awk(如果需要)来处理您的文件并将其输出到另一个文件中。
或者使用您选择的脚本语言。在 Ruby 中,它看起来像这样
As far as I know, TextMate cannot do what you want to achieve. However, as you already mentioned you want to process your file, i.e. you should write a simple script which does it.
If you need to parse such files very often it may be worth writing a command for TextMate (Bundles > Bundle Editor > Show Bundle Editor > New Command).
If it's a one time activity you are probably better off to do everything from the command line, i.e. use grep, sed and awk (if necessary) to process your file and output it into another one.
Or use the scripting language of your choice. In Ruby it would look something like