|
|
@ -80,72 +80,4 @@ public class MesNumberRuleMatchRegularExpressionService implements IMesNumberRul
|
|
|
|
String matchRule = "1574110000*";
|
|
|
|
String matchRule = "1574110000*";
|
|
|
|
System.out.println(sn.matches(matchRule));
|
|
|
|
System.out.println(sn.matches(matchRule));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 装配件BarCode规则是否匹配
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="ruleStr">规则字串</param>
|
|
|
|
|
|
|
|
/// <param name="barCode">条码</param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
public static Boolean BarcodeRuleIsMatch(String ruleStr, String barCode)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (String.IsNullOrEmpty(ruleStr))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!ruleStr.Contains("*") && !ruleStr.Contains("?") && !ruleStr.Contains(","))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ruleStr.ToLower() == barCode.ToLower())
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
///首先规则可以是多种以逗号隔开,将其先拆到数组中
|
|
|
|
|
|
|
|
string[] rules = ruleStr.Split(new char[] { ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
///以当前扫入的条码匹配每一条规则,当某条匹配上后直接返回true
|
|
|
|
|
|
|
|
foreach (var rule in rules)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (rule.Contains("yyyyMMdd"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Regex reg = new Regex(@"\d{4}[年/.-]?\d{1,2}[月./-]?(\d{1,2}日?)?");
|
|
|
|
|
|
|
|
MatchCollection mc = reg.Matches(barCode);
|
|
|
|
|
|
|
|
if (reg.IsMatch(barCode.ToLower())) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (rule.Contains("yyyy.MM.dd"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Regex reg = new Regex(@"\d{4}[年/.-]?\d{1,2}[月./-]?(\d{1,2}日?)?");
|
|
|
|
|
|
|
|
MatchCollection mc = reg.Matches(barCode);
|
|
|
|
|
|
|
|
if (reg.IsMatch(barCode.ToLower())) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (rule.Contains("yyyy/MM/dd"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Regex reg = new Regex(@"\d{4}[年/.-]?\d{1,2}[月./-]?(\d{1,2}日?)?");
|
|
|
|
|
|
|
|
MatchCollection mc = reg.Matches(barCode);
|
|
|
|
|
|
|
|
if (reg.IsMatch(barCode.ToLower())) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (rule.Contains("yyyy-MM-dd"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Regex reg = new Regex(@"\d{4}[年/.-]?\d{1,2}[月./-]?(\d{1,2}日?)?");
|
|
|
|
|
|
|
|
MatchCollection mc = reg.Matches(barCode);
|
|
|
|
|
|
|
|
if (reg.IsMatch(barCode.ToLower())) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (rule.Contains("yyyy-MM-dd hh:mm:ss"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Regex reg = new Regex(@"\d{4}[年/.-]?\d{1,2}[月./-]?(\d{1,2}日?)?");
|
|
|
|
|
|
|
|
MatchCollection mc = reg.Matches(barCode);
|
|
|
|
|
|
|
|
if (reg.IsMatch(barCode.ToLower())) return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string ruleNoSpecialChar = StringUtil.TrimSpecialChars2(rule);
|
|
|
|
|
|
|
|
string barcodeNoSpecialChar = StringUtil.TrimSpecialChars2(barCode);
|
|
|
|
|
|
|
|
///将规则转换为正则表达式,使用正则表达式进行匹配,正则中去除二维码的起始特殊符号
|
|
|
|
|
|
|
|
//update by huxj 2020.04.07 添加二维码前缀正则匹配
|
|
|
|
|
|
|
|
var regStr = "^" + ruleNoSpecialChar.ToLower().Replace(")", @"\)").Replace("?", @"(?:.|\n){1}").Replace("*", @"(?:.|-\n)*").Replace("[", @"\[") + "$";
|
|
|
|
|
|
|
|
//Regex rgx = new Regex("^" + ruleNoSpecialChar.ToLower().Replace("?", @"(?:.|\n){1}").Replace("*", @"(?:.|\n)*") + "$");
|
|
|
|
|
|
|
|
Regex rgx = new Regex(regStr);
|
|
|
|
|
|
|
|
//end update
|
|
|
|
|
|
|
|
if (rgx.IsMatch(barcodeNoSpecialChar.ToLower())) return true;
|
|
|
|
|
|
|
|
if (rule == barCode) return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|