private void ShowRegexResult()
        {
            //Get regmatches
            List <MatchElement> result = RegMatch.MatchesList(
                txt_document.Text.ToString(),
                txt_exp.Text.ToString(),
                txt_sortMatch.Text,
                Convert.ToInt32(txt_match.Value),
                txt_sortGroup.Text,
                Convert.ToInt32(txt_group.Value));

            txt_result.Text = RegMatch.ShowMatchCases(result, txt_document);
        }
Exemple #2
0
        private void CapturedList_Load(object sender, EventArgs e)
        {
            dtResult = new DataTable();
            List <Parameter> paras = mainForm.CurrentSolution.Parameters;

            string[] columnNames = new string[paras.Count() + 1];

            //Create Columns
            dtResult.Columns.Add("File Names");
            columnNames[0] = "File Names";
            int c = 0;

            foreach (Parameter p in paras)
            {
                int nameSuffix = 0;
                c++;
                if (dtResult.Columns.Contains(p.Display))
                {
                    nameSuffix++;
                    dtResult.Columns.Add(p.Display + nameSuffix.ToString());
                    columnNames[c] = p.Display + nameSuffix.ToString();
                }
                else
                {
                    dtResult.Columns.Add(p.Display);
                    columnNames[c] = p.Display;
                }
            }

            //Get datarows into datatable
            int indexDtRow = -1;

            foreach (string[] s in pdfTxtArray)
            {
                //Get matches into parameter
                int addRows = 0;
                foreach (Parameter p in paras)
                {
                    List <MatchElement> result = RegMatch.MatchesList(s[1], p.RegExp, p.SortOfMatches, p.IndexOfMatches, p.SortOfGroups, p.IndexOfGroups);
                    p.Matches = result;

                    if (p.Matches != null)
                    {
                        addRows = p.Matches.Count() > addRows?p.Matches.Count() : addRows;

                        foreach (MatchElement m in p.Matches)
                        {
                            if (m.Groups != null)
                            {
                                addRows = m.Groups.Count() > addRows?m.Groups.Count() : addRows;
                            }
                        }
                    }
                    else
                    {
                        List <MatchElement> blankMatch = new List <MatchElement>();
                        blankMatch.Add(new MatchElement {
                            Index = -1, Value = "Null", Groups = null
                        });
                        p.Matches = blankMatch;
                    }
                }

                if (addRows > 0)
                {
                    //Fill blank datarows into datatable
                    for (int i = 1; i <= addRows; i++)
                    {
                        DataRow dr = dtResult.NewRow();
                        dr[0] = s[0];
                        dtResult.Rows.Add(dr);
                    }

                    //Fill actual data into datatable per index
                    c = 0;
                    foreach (Parameter p in paras)
                    {
                        c++;
                        List <string> values = new List <string>();
                        foreach (MatchElement m in p.Matches)
                        {
                            if (m.Groups != null)
                            {
                                foreach (GroupElement g in m.Groups)
                                {
                                    values.Add(g.Value);
                                }
                            }
                            else
                            {
                                values.Add(m.Value);
                            }
                        }

                        for (int i = 1; i <= addRows; i++)
                        {
                            if (i <= values.Count())
                            {
                                dtResult.Rows[i + indexDtRow][columnNames[c]] = values[i - 1];
                            }
                        }
                    }

                    indexDtRow = indexDtRow + addRows;
                }
            }

            this.Text = "Captured - " + mainForm.CurrentSolution.Name;
            GridCapturedList.DataSource = dtResult;
            label_status.Text           = string.Format("Total read {0} files, {1} columns and {2} rows were loaded...", pdfTxtArray.Count(), paras.Count(), GridCapturedList.Rows.Count - 1);
        }
Exemple #3
0
        public static List <MatchElement> MatchesList(string input, string pattern, string SortMatches, int IndexMatch, string SortGroups, int IndexGroup)
        {
            List <MatchElement> MatchesList = RegMatch.MatchesList(input, pattern);

            if (MatchesList != null)
            {
                List <MatchElement> FilteredMatches = new List <MatchElement>();
                if (SortMatches == "Descending")
                {
                    if (MatchesList != null)
                    {
                        MatchesList.Reverse();
                    }
                }

                if (IndexMatch > -1)
                {
                    if (IndexMatch + 1 > MatchesList.Count())
                    {
                        IndexMatch = MatchesList.Count() - 1;
                    }
                    FilteredMatches.Add(MatchesList[IndexMatch]);
                }
                else
                {
                    FilteredMatches = MatchesList;
                }

                if (SortGroups == "Descending")
                {
                    foreach (MatchElement e in FilteredMatches)
                    {
                        if (e.Groups != null)
                        {
                            e.Groups.Reverse();
                        }
                    }
                }

                if (IndexGroup == -2)
                {
                    foreach (MatchElement e in FilteredMatches)
                    {
                        e.Groups = null;
                    }
                }
                else if (IndexGroup == -1)
                {
                }
                else
                {
                    foreach (MatchElement e in FilteredMatches)
                    {
                        if (e.Groups != null)
                        {
                            List <GroupElement> FilteredGroup = new List <GroupElement>();

                            if (IndexGroup + 1 > e.Groups.Count())
                            {
                                IndexGroup = e.Groups.Count() - 1;
                            }

                            FilteredGroup.Add(e.Groups[IndexGroup]);
                            e.Groups = FilteredGroup;
                        }
                        else
                        {
                            e.Groups = null;
                        }
                    }
                }

                return(FilteredMatches);
            }

            return(null);
        }