Example #1
0
        private void SearchRegexPattern()
        {
            if (tt == null || string.IsNullOrEmpty(Value)) return;

            string text;
            List<Place> charIndexToPlace;
            var range = fastColoredTB.Range;
            range.GetText(out text, out charIndexToPlace);

            MatchCollection mc = MatchesWithTimeout(tt, text, 5000);
            if (mc == null) {
                tbResult.Text = "Операция прервана по таймауту.";
                return;
            }

            tbRegexCount.Text = mc.Count.ToString();
            int pos = fastColoredTB.SelectionStart;
            bool waspos = false;
            range.ClearStyle(fastColoredTB.GreenSelectionStyle, fastColoredTB.BlueSelectionStyle);
            fastColoredTB.SyntaxHighlighter.HighlightSyntax(fastColoredTB.Language, range);
            string result = "";
            foreach (Match m in mc) {
                Group group = m.Groups[0];
                Range r = new Range(range.tb) {
                    Start = charIndexToPlace[group.Index],
                    End   = charIndexToPlace[group.Index + group.Length]
                };
                r.SetStyleOwerwrite(fastColoredTB.BlueSelectionStyle);
                bool skipfisrt = false;
                foreach (Group g in m.Groups) {
                    if (!skipfisrt) { skipfisrt = true; continue; }
                    Range rg = new Range(range.tb) {
                        Start = charIndexToPlace[g.Index],
                        End   = charIndexToPlace[g.Index + g.Length]
                    };
                    rg.SetStyleOwerwrite(fastColoredTB.GreenSelectionStyle);
                }
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (!waspos) {
                    int posr = fastColoredTB.PlaceToPosition(r.Start);
                    if (pos < posr) {
                        // ReSharper disable once RedundantAssignment
                        waspos = true;
                        fastColoredTB.SelectionStart = posr;
                        fastColoredTB.DoCaretVisible();
                        result = m.Groups[cbResultIndex.SelectedIndex].Value;
                        break;
                    }
                }
            }
            if (chkHTML2Text.Checked) result = HtmlRemoval.Html2Text(result);
            tbResult.Text = result;
            fastColoredTB.YellowSelection    = true;
            fastColoredTB.SelectionAfterFind = true;
            fastColoredTB.LightYellowSelect(tt);
        }