Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.

C#
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);
                    }
                }
            }
}
Posted

1 solution

"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?
 
Share this answer
 
Comments
ErwinLulu 3-Nov-15 3:22am    
Hmm I want some regular expression that will find this..

7x8 or 7 x 8 (where 7 or 8 is any number that between the "x" character

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900