简体   繁体   English

如何使用正则表达式 Notepad++ 提取 2 个模式之间的所有字符串?

[英]How to extract all the strings between 2 patterns using regex Notepad++?

Extract all the string between 2 patterns:提取 2 个模式之间的所有字符串:

Input:输入:

test.output0    testx.output1    output3    testds.output2(\t)

Output: Output:

output0    output1    ouput3   output2

Note: (" ") is the tab character.注意:(" ") 是制表符。

You may try:你可以试试:

\.\w+$

Explanation of the above regex:上述正则表达式的解释:

  • \. - Matches . - 比赛. literally.字面上地。 If you do not want .如果你不想. to be included in your pattern;包含在您的模式中; please use (?<=\.) or simply remove .请使用(?<=\.)或简单地删除. . .
  • \w+ - Matches word character [A-Za-z0-9_] 1 or more time. \w+ - 匹配单词字符[A-Za-z0-9_] 1 次或更多次。
  • $ - Represents end of the line. $ - 代表行尾。

You can find the demo of the regex in here.你可以在这里找到正则表达式的演示。

Result Snap:结果快照:

图示

EDIT 2 by OP: OP编辑2:

According to your latest edit;根据您的最新编辑; this might be helpful.这可能会有所帮助。

.*?\.?(\w+)(?=\t)

Explanation:解释:

  • .*? - Match everything other than new line lazily . -懒惰地匹配新行以外的所有内容。
  • \.? - Matches . - 比赛. literally zero or one time.从字面上看是零次或一次。
  • (\w+) - Represents a capturing group matching the word-characters one or more times. (\w+) - 表示与单词字符匹配一次或多次的捕获组。
  • (?=\t) - Represents a positive look-ahead matching tab . (?=\t) - 表示正向前瞻匹配tab
  • $1 - For the replacement part $1 represents the captured group and a white-space to separate the output as desired by you. $1 - 对于替换部件, $1代表捕获的组和一个空格,用于根据您的需要分隔 output。 Or if you want to restore tab then use the replacement $1\t .或者,如果您想恢复tab ,请使用替换$1\t

Please find the demo of the above regex in here.请在此处找到上述正则表达式的演示。

Result Snap 2:结果快照 2:

在此处输入图像描述

Try matching on the following pattern:尝试匹配以下模式:

Find: (?<![^.\s])\w+(?!\S)

Here is an explanation of the above pattern:以下是对上述模式的解释:

(?<![^.\s])  assert that what precedes is either dot, whitespace, or the start of the input
\w+          match a word
(?!\S)       assert that what follows is either whitespace of the end of the input

Demo演示

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

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