I'm just getting started with Regex and want to select text that has ONLY one tab in front between two specific strings.
In that case I want to select text that is between ABC
and CDE
(don't select ABC
and CDE
) and has ONLY one tab in front of it. So I want to select Rotterdam
, Amsterdam
, China
and Japan
and do not select e.g. Hello
and I have two tabs in front of me
because they have two tabs.
EFGADADA
Hello
EFGHI
Oslo
Australia
EFGHI
ABC
Rotterdam
Amsterdam
China
Japan
Hello
I have two tabs in front of me
CDE
Oslo
Australia
I already have this which deselects everything that has two tabs in front of it:
(?<!\t\t(.?) )[ a-zA-ZäöüÄÖÜßé@.()&-/"“]
I know, this selects also ABC
, CDE
and EFGHI
, which of course, don't have any tabs in front of them but thats fine because between ABC
and CDE
is only Text that has tabs in front of it.
Btw. I use the Regex inside Power Automate Desktop, if that matters.
CodePudding user response:
Assuming this tool supports .NET regex, you could use a variable length lookbehind.
(?<=(?:\r?\n|^)ABC(?:.*\r?\n\t)*)\S.*
See this demo at regex101 (update: refactored for working without multiline mode)
There is no check included for CDE
afterwards which was not in your current pattern.
regex-part | matches |
---|---|
(?<= |
negative lookbehind to look towards the left for a subpattern |
(?:\r?\n|^)ABC |
(?: non capturing group ) containinglinebreak (CR)LF or ^ start, followed by ABC |
(?:.*\r?\n\t)* |
(?: non capturing group ) * any amountcontaining lines followed by at least one \t tab |
)\S.* |
end of subpattern; match a non-whitespace \S and anything .* |