123456789101112131415161718192021222324252627282930313233 |
- using System.Text.RegularExpressions;
- namespace Alchemy.Core.Services
- {
- public class RegexService
- {
- /// <summary>
- /// 判断正则表达式
- /// </summary>
- /// <param name="strRaw"></param>
- /// <param name="strFormat"></param>
- /// <returns></returns>
- public static bool IsMatch(string strRaw, string strFormat)
- {
- Regex regex = new Regex(strFormat, RegexOptions.None);
- return regex.IsMatch(strRaw);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="strInput"></param>
- /// <param name="strStart"></param>
- /// <param name="strEnd"></param>
- /// <returns></returns>
- public static string GetStringBetween(string strInput, string strStart, string strEnd)
- {
- string pattern = Regex.Escape(strStart) + "(.*?)" + Regex.Escape(strEnd);
- Match match = Regex.Match(strInput, pattern);
- if (match.Success)
- return match.Groups[1].Value;
- return string.Empty;
- }
- }
- }
|