如何在reg表达式中搜索[0-9] x [0-9] [英] How do search this in reg expression [0-9] x [0-9]

查看:100
本文介绍了如何在reg表达式中搜索[0-9] x [0-9]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在reg表达式[0-9] x [0-9] ||中搜索[0-9] x [0-9]。



我的目标是搜索并验证语句是否是乘法语句。我的正则表达方式不是很好。



How do search this in reg expression [0-9] x [0-9] || [0-9]x[0-9].

My goal here is to search and verify if the statement is a multiplication statement. I'm not really good in regular expression.

public void CheckMultiplicationEntity()
        {
            int lineno = 0;
            bool start = false;
            foreach (string line in _contentList)
            {
                lineno++;
                if (line.Contains("<text>"))
                {
                    start = true;
                }
                if (start)
                {
                    foreach (Match match in Regex.Matches(line, @"([0-9]x[0-9]|[0-9\sx\s0-9]"))
                    {
                        List<ErrorModel> errorlist = ErrorList;
                        ErrorModel errorModel = new ErrorModel()
                        {
                            LineNumber = lineno,
                            ErrorMessage = "Please check \"x\" should ×",
                            Text = ShortenText(match.Value)
                        };
                        errorlist.Add(errorModel);
                    }
                }
            }
}

推荐答案

我的正则表达式并不是很好



的确如此。 :D



怎么样: [0-9] \s * x \ * * [0-9]



虽然它只处理整数(最多为base10),而不是浮点和其他格式。



你到底需要什么?
"I'm not really good in regular expression"

Indeed. :D

How about: [0-9]\s*x\s*[0-9]

Though that handles only integers (up to base10), not floating-point and other formats.

What exactly do you need?


这篇关于如何在reg表达式中搜索[0-9] x [0-9]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆