Exemplo n.º 1
0
        public List <string> GetNextLevelUrl(string parentUrl, string html, string urlRule)
        {
            ///category-<Regex:\S+>/goods-<Regex:\d+>.html
            List <string> resultUrls  = new List <string>();
            string        urlTempRule = "";

            if (urlRule.StartsWith("<Regex:"))
            {
                urlTempRule = @"(?<=[href=|src=|open(][\W])";
                //处理前缀
                string strPre = urlRule.Substring(urlRule.IndexOf("<Regex:") + 7, urlRule.IndexOf(">") - 7);
                urlTempRule += strPre;
                //处理中间内容
                string cma = @"(?<=<Common:)\S+?(?=>)";

                Regex           cmas = new Regex(cma, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                MatchCollection cs   = cmas.Matches(urlRule);
                foreach (Match ma in cs)
                {
                    urlTempRule += @"(\S*)" + ma.Value.ToString();
                }

                //处理后缀
                if (Regex.IsMatch(urlRule, "<End:"))
                {
                    string s = urlRule.Substring(urlRule.IndexOf("<End:") + 5, urlRule.Length - urlRule.IndexOf("<End:") - 6);
                    urlTempRule += @"(\S*)" + s;
                }
                else
                {
                    urlTempRule += @"(\S[^'"">]*)(?=[\s'""])";
                }
            }
            else
            {
                urlTempRule = @"(?<=[href=|src=|open(][\W])" + RegexString.RegexReplaceTrans(urlRule) + @"(\S[^'"">]*)(?=[\s'""])";
            }
            MatchCollection matchs = Regex.Matches(html, urlTempRule, RegexOptions.IgnoreCase | RegexOptions.Multiline);

            foreach (Match item in matchs)
            {
                string url = GetNextUrl(item.Value, parentUrl);
                if (!resultUrls.Contains(url))
                {
                    resultUrls.Add(url);
                }
            }
            return(resultUrls);
        }
Exemplo n.º 2
0
        private string GetRegString(TaskColumnItem temp)
        {
            string strCut = string.Empty;

            strCut += "(?<" + temp.DataTextType.Value + ">" + RegexString.RegexReplaceTrans(temp.StartPos.Value) + ")";
            switch (temp.LimitSign)
            {
            case EnumGloabParas.EnumLimitSign.LimitSign1:
                strCut += ".*?";
                break;

            case EnumGloabParas.EnumLimitSign.LimitSign2:
                strCut += "[^<>]*?";
                break;

            case EnumGloabParas.EnumLimitSign.LimitSign3:
                strCut += "[\\u4e00-\\u9fa5]*?";
                break;

            case EnumGloabParas.EnumLimitSign.LimitSign4:
                strCut += "[^\\x00-\\xff]*?";
                break;

            case EnumGloabParas.EnumLimitSign.LimitSign5:
                strCut += "[\\d]*?";
                break;

            case EnumGloabParas.EnumLimitSign.LimitSign6:
                strCut += "[\\x00-\\xff]*?";
                break;

            case EnumGloabParas.EnumLimitSign.LimitSign7:
                strCut += temp.LimitSignText.ToString();
                break;

            default:
                strCut += "[\\S\\s]*?";
                break;
            }
            strCut += "(?=" + RegexString.RegexReplaceTrans(temp.EndPos.Value) + ")";
            return(strCut);
        }
Exemplo n.º 3
0
 public abstract void Apply(RegexString regexString);
 /// <summary>
 /// Constructs a new CommandExecutorAttribute using the given <see cref="RegexString"/>s to match input to the command
 /// </summary>
 /// <param name="description">A string describing the command</param>
 /// <param name="commandMatcher">A required RegexString that input must match for the command to be run</param>
 /// <param name="matcherOptions">A RegexStringOptions enum defining how the matcher will behave</param>
 /// <param name="friendlyName">An optional human-readable name for the command</param>
 public CommandExecutorAttribute(string description, string commandMatcher, RegexStringOptions matcherOptions, string friendlyName = null)
 {
     Description    = description;
     CommandMatcher = new RegexString(commandMatcher, matcherOptions);
     FriendlyName   = friendlyName;
 }