Reputation: 115
I have the following text:
[atdSd[asdasd<4REGEH22>asdosy] ***oopprefs[ew<16REGEH30>rdtr]pppp555b
My matches should be as follows:
[asdasd<4REGEH22>asdosy]
[ew<16REGEH30>rdtr]
I have tried to make it on my own but the result was:
[atdSd[asdasd<4REGEH22>asdosy]
[ew<16REGEH30>rdtr]
I am using the following expression:
\[\S+<(\d+)REGEH(\d+)>\S+\]
The conditions are:
[asdSd[asdasd<4REGEH23>asdUsd]
should match [asdasd<4REGEH23>asdUsd]
An example that should yield no matches
[atdSd[<4REGEH22>asdosy] ***oopprefs[ew<16REGEH>rdtr]pppp555b
How can I match the inner parentheses?
Upvotes: 1
Views: 160
Reputation: 5658
var st = "[atdSd[asdasd<4REGEH22>asdosy] ***oopprefs[ew<16REGEH30>rdtr]pppp555b";
List<string> result = new List<string>
(Regex.Matches(st, @"\[[^[]+REGEH.*?\]")
.Cast<Match>()
.Select(x => x.Value)
.ToList());
// [asdasd<4REGEH22>asdosy] [ew<16REGEH30>rdtr]
Upvotes: 1
Reputation: 3114
How about this?
\[[^\s\[]+<(\d+)REGEH(\d+)>[[^\s\[]+\]
Basically replaced the \S
with [^\s\[]
, ie a negated char class matching for not whitepsace chars and, crucially - for not [
.
Upvotes: 0