Copy only the search expression results from a textfile in notepad++

自闭症网瘾萝莉.ら 提交于 2019-12-20 10:39:10

问题


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

Just like:

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

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

How do I do it?


回答1:


[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 ].

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

  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.

Here's how to delete non-pattern lines and preserve only the patterns from lines with the pattern.

  1. Bookmark all lines with the pattern:

  1. Delete the un-bookmarked lines, so that now you only have lines with the pattern.

  1. Now you can run the regex find and replace as above (first part of answer) to keep only the pattern from the remaining lines.


来源:https://stackoverflow.com/questions/29218324/copy-only-the-search-expression-results-from-a-textfile-in-notepad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!