仅从记事本 ++ 中的文本文件复制搜索表达式结果 [英] Copy only the search expression results from a textfile in notepad++

查看:32
本文介绍了仅从记事本 ++ 中的文本文件复制搜索表达式结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个源代码,只想复制我用正则表达式找到的字符串.

I have a source code and want simply to copy the strings which I find with an regular expression.

就像:

asdladhsfhjk-hello1-asdlkajhsd
asdsa-hello3-asdhjkl
asdölkj-hello5-

我只想从文本中复制 -helloX-.而不是线路..

that I simply want to copy the -helloX- from the text. And not the line..

我该怎么做?

推荐答案

[update:如果您正在处理具有以下特征的文件,请参阅下面的扩展说明1. 带图案的线条和不带图案的线条2.你想擦除所有没有图案的线条和3. 只保留其余行的模式].

[update: see extended instructions below if you are working with a file that has 1. lines with and lines without the pattern and 2. you want to erase all lines without the pattern and 3. only preserve the pattern from the remaining lines ].

做一个正则表达式查找和替换,搜索模式为^.*?(-hello[0-9]+-).*$,替换为\1.

Do a regular expression Find and Replace, with the search pattern as ^.*?(-hello[0-9]+-).*$ and the replacement as \1.

  1. 这会在任何行的开头找到一个非贪婪匹配(匹配将尽可能小),例如:^.*?.
  2. 然后你的模式在 () 中,这样它就可以在一个捕获组中被捕获.
  3. 然后我们匹配 .*$ 行的其余部分.
  4. \1()s中匹配的捕获组的内容.
  1. That finds a non-greedy match (match will be as small as it can) at the beginning of the line for anything, like so: ^.*?.
  2. Then your pattern is in (), so that it can be captured in a capture group.
  3. Then we match the rest of the line .*$.
  4. The \1 is the contents of the capture group matched in the ()s.

<小时>

这里是如何删除非模式行并仅保留具有模式的行中的模式.

  1. 为所有行添加样式书签:

  1. 删除未添加书签的行,以便现在您只有带有该模式的行.

  1. 现在您可以像上面一样运行正则表达式查找和替换(答案的第一部分)以仅保留其余行中的模式.

这篇关于仅从记事本 ++ 中的文本文件复制搜索表达式结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆