Regex Question - lookbehind with wildcard

Carl Graff 1 Reputation point
2022-05-06T05:50:46.51+00:00

I have a line of text like this:
<tab>some text<tab>some more text<tab>one||two||three<tab>more text<tab>red||green||blue

I want to find the indexes at the bolded o and r.

My attempt would be if possible:


pattern = @"(?<=\t.*)\|\|"

foreach (Match match in Regex.Matches(text, pattern)
Console.WriteLine("Found '{0}' at position {1}", match.Value, match.Index);


Even better would be to match the entire contents of the fields:
one||two||three and red||green||blue

Thanks for your assistance

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-05-06T06:07:01.013+00:00

    Check this pattern:

    (?<=\t|^)[^\t]+?\|\|[^\t]+?\|\|[^\t]+?(?=\t|$)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.