using System.Text.RegularExpressions;
|
|
namespace HStation.Service
|
{
|
/// <summary>
|
/// 正则辅助类
|
/// </summary>
|
internal static class RevitJsonRegexHelper
|
{
|
private const string _numericPattern = @"[+-]?\d*[.]?\d*";//数值模式
|
private const string _numericAbsolutePattern = @"^[+-]?\d*[.]?\d*$";//数值绝对模式
|
|
/// <summary>
|
/// 匹配第一个数值
|
/// </summary>
|
public static bool MatchNumeric(this string numericStr, out double numeric)
|
{
|
numeric = 0;
|
if (string.IsNullOrEmpty(numericStr))
|
{
|
return false;
|
}
|
var match = Regex.Match(numericStr, _numericPattern);
|
if (string.IsNullOrEmpty(match.Value))
|
{
|
return false;
|
}
|
if (Regex.IsMatch(match.Value, _numericAbsolutePattern))
|
{
|
numeric = double.Parse(match.Value);
|
return true;
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 匹配第一个数值
|
/// </summary>
|
public static bool MatchNumeric(this JToken jtoken, out double numeric)
|
{
|
numeric = 0;
|
if (jtoken == null)
|
{
|
return false;
|
}
|
return jtoken.ToString().MatchNumeric(out numeric);
|
}
|
|
|
}
|
}
|