N
N
Nulltiton2022-04-08 11:55:37
Regular Expressions
Nulltiton, 2022-04-08 11:55:37

Why doesn't the regular expression that works in regex101 work?

There is a ready-made regular expression that works as shown in the figure, but when you write the same expression in C#, it outputs the entire text of the first line.
624ff80b12930810482473.png
Code in C#:

for (int page = 1; page <= pdfReader.NumberOfPages; page++)
                                {
                                    string pattern = @"(?<=\s)\d(\.|-(\d))\s.*" + surname + @".*\d";
                                    ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
                                    string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);

                                    foreach (Match match in Regex.Matches(currentText, pattern, RegexOptions.IgnoreCase))
                                    {
                                        for (int i = 0; i < match.Groups.Count; i++)
                                            resultText += match.Value + "\n";
                                    }
                                    text.Append(resultText);
                                }

PS Already read about it here https://qna.habr.com/q/703268 , but it didn't help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question