C# WPF RegEx - only numbers, digits from 0 to 4 or numbers and letters.

Markus Freitag 3,786 Reputation points
2020-10-05T08:57:46.487+00:00

Hello,

txtInput.Text = "[)>RS06" + (char)29 + "11V62970814" + (char)29 + "P1234567890" + (char)29 + "16SZZ" + (char)29 + "1P0793" + (char)29 + "6P001" + (char)29 + "Q375RSEOT";

 private string RegExprFEOrder  
        {  
            get { return @"11V([A-Z0-9]{8})";  } //@"@1T([A-Za-z0-9/_,#\:\%\-\*\+\.]{1,17})@"; }  
        }  
  
        private string RegExprMatNumber  
        {  
            get { return @"P([0-9]\d{0,10})"; } //(NAR)\d{3})"; }  
        }  
  
        private string RegExprIndex  
        {  
            get { return @"16S([-A-Z0-9]{1,2})"; }    // with special character!  
        }  
  
        private string RegExprLPLayout  
        {  
            get { return @"1P([A-Z0-9]{4})"; }  
        }  
  
        private string RegExprLPVariante  
        {  
            get { return @"6P([A-Z0-9]{3})"; }  
        }  
  
        private string RegExprMenge  
        {  
            get { return @"Q([A-Z0-9]\d{0,10})"; }  
        }  

30159-121.png

I need a range for RegEx. How can I do it?
get { return @"1P([A-Z0-9]{4})"; }

get { return @"1P([A-Z0-9]{0,4})"; } not work

   matchMatLabel = Regex.Match(item, regEx);  
  
                if (matchMatLabel.Success)  
                {  
                    Trace.WriteLine("Value  = " + matchMatLabel.Value);  
                    Trace.WriteLine("Length = " + matchMatLabel.Length);  
                    Trace.WriteLine("Index  = " + matchMatLabel.Index);  
  
  
                    if (matchMatLabel.Groups.Count > 1)  
                    {  
                        value1 = matchMatLabel.Groups[1].ToString();  
                        value2 = matchMatLabel.Groups[2].ToString();  
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
{count} votes

Accepted answer
  1. Markus Freitag 3,786 Reputation points
    2020-10-06T05:33:31.207+00:00

    txtInput.Text = "[)>RS06" + (char)29 + "11V62970814" + (char)29 + "P1234567890" + (char)29 + "16SZZ" + (char)29 + "1P0793" + (char)29 + "6P001" + (char)29 + "Q375RSEOT";

    Hello,
    I have a string like this. (to see above or below)

    or like this

    txtInput.Text = "[)>RS06" + (char)29 + "P1234567890" + (char)29 + "16SZZ" + (char)29 + "1P0793" + (char)29 + "6P001" + (char)29 + "Q375RSEOT";
    More or less or different place. So I think the best is RegEx.

    So I need all variables and values. (Prefix, Value)

    get { return @"16S([-A-Z0-9]{1,2})"; } // with special character!

    16S is prefix or 1P is prefix.

    get { return @"1P([A-Z0-9]{0,4})"; } not work

    1P can be 4 digits or only 2 or 3. But if I make a range is not work, no match, why?

    • How I can define valid values A-Z, 0-9 and the count is from 0 to 4 ?
    • How I can define valid values A-Z, 0-9, -, @ or # and the count is from 1 to 2 ? Specials values -, @ or #

    Or do you see a better way for analysis this string?

    My idea was.
    Split first the whole string, then check each items with RegEx.

    Thanks in advance for your help.
    Best regards Markus


0 additional answers

Sort by: Most helpful