【问题标题】:proper regular expression to extract a specific number from long string正确的正则表达式从长字符串中提取特定数字
【发布时间】:2021-11-09 14:59:49
【问题描述】:

输入字符串:|1|!!!ABC|9.56!|x10e3/uL||0.1m1v0|||||XDS||202f914120247|01

需要提取:9.56

Dim matchResult = Regex.Match(inputString, "|(\d+(.\d+)?) !") 好像不行

【问题讨论】:

    标签: .net nsregularexpression


    【解决方案1】:

    试试这个:\|(\d{1,}(\.\d{1,})?)!\|

    using System;
        
    using System.Text.RegularExpressions;
    
    public class Example
    {
        public static void Main()
        {
            string pattern = @"\|(\d{1,}(\.\d{1,})?)!\|";
            string input = @"|1|!!!ABC|9.56!|x10e3/uL||0.1m1v0|||||XDS||202f914120247|01";
            RegexOptions options = RegexOptions.Multiline;
            var m = Regex.Matches(input, pattern, options)[0];
            var g = m.Groups[1];
            Console.WriteLine("'{0}'", g.Value);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-24
      • 2019-03-13
      • 1970-01-01
      • 2011-05-10
      • 2014-08-25
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多