英文:
Regex select names in next lines after match (until...)
问题
Match
Fridolin
Marten
Connection
(?<=Match[\r\n]+\t\t?\t?\t?\t?)([ a-zA-ZäöüÄÖÜßé0-9\.-/\-])+
英文:
I have a text file with different levels (scructured by tabs) and I need to select certain values out of it. Here is an example. I tried this for a very long time, but I can't find any solution.
Connection
Match
Fridolin
Marten
Connection
Inventory
Fill Up
Fill Up
Match
Peter
Marcus
Storage
Room 1
Room 2
Room 3
Match
Albert
Jonas
Hans
List
Match
Peter
Marcus
I want to select every name in the following lines after "Match" (which has the same amount of tabs in front of it) until the next level (different amount of tabs) starts. In this case I want to select the names that are listed after the word "Match". Until (for example) "Connection" pops up and the amount of tabs in front of it (level) changes. The Names that follow "Match" are always on the same level. I can't use multiline for this.
Match
Fridolin
Marten
Connection
(?<=Match[\r\n]+\t\t?\t?\t?\t?)([ a-zA-ZäöüÄÖÜßé0-9\.-/\-])+
I have already this regex, which selects at least the first name that follows "Match". I don't know how to select the next names and stop if the level changes.
答案1
得分: 2
以下是代码部分的翻译:
(?<=Match)\n(\s+)\w+(?:\n\w+)+
请注意,这是正则表达式,用于匹配文本中的特定模式。如果需要有关这个正则表达式的更多信息,请让我知道。
英文:
Try this:
(?<=Match)\n(\s+)\w+(?:\n\w+)+
The regular expression matches as follows:
Node | Explanation |
---|---|
(?<= |
look behind to see if there is: |
Match |
'Match' |
) |
end of look-behind |
\n |
'\n' (newline) |
( |
group and capture to \1: |
\s+ |
whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) |
) |
end of \1 |
\w+ |
word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) |
(?: |
group, but do not capture (1 or more times (matching the most amount possible)): |
\n |
'\n' (newline) |
\1 |
what was matched by capture \1 |
\w+ |
word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) |
)+ |
end of grouping |
答案2
得分: 1
尝试:
```none
\b匹配\n((\s*).*\n(?:.*(?:\n|\Z))*)
这将匹配匹配
,后面跟随换行,然后是任意数量的空格作为捕获组1。然后使用此捕获组来匹配其他行。
<details>
<summary>英文:</summary>
Try:
```none
\bMatch\n((\s*).*\n(?:.*(?:\n|\Z))*)
This will match Match
, following newline and then any number of whitespaces as capturing group 1. Then use this capturing group to match other lines.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论