Home > Software design >  how to write any 9 numbers with one character in regex
how to write any 9 numbers with one character in regex

Time:06-11

could someone help me solve this issue? I want to check any 9 numbers with 'v' or 'V'.(in C#)

example : 124345321V 584343234v 125334134V

CodePudding user response:

Use this one here:

\d{9}[v|V]$

CodePudding user response:

I don't know C# but the normal regex would be:

[0-9]{9}[vV]

CodePudding user response:

you have to use \d as any digit and {9} that means the 9 digits. then in [] you set lower case v and upper case V that match any of them

\d{9}[Vv]

the code (From https://regex101.com) :

using System;
using System.Text.RegularExpressions;

public class Example
{
    public static void Main()
    {
        string pattern = @"\d{9}[Vv]";
        string input = @"example : 124345321V 584343234v 125334134V";
        RegexOptions options = RegexOptions.Multiline;
        
        foreach (Match m in Regex.Matches(input, pattern, options))
        {
            Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
        }
    }
}

CodePudding user response:

string strRegex = @"\d{9}[Vv]";
Regex rg = new Regex(strRegex);
var number = "124345321V";
MatchCollection matchedAuthors = rg.Matches(number);  
  • Related