question

CarlGraff-0421 avatar image
0 Votes"
CarlGraff-0421 asked Viorel-1 answered

Regex Question - lookbehind with wildcard

I have a line of text like this:
<tab>some text<tab>some more text<tab>**o*ne||two||three<tab>more text<tab>r*ed||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




dotnet-csharp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sorry about the formatting the text line should be:
<tab>some text<tab>some more text<tab>one||two||three<tab>more text<tab>red||green||blue

with the desired indexes at one and red

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

Check this pattern:

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


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.