-2

I am a beginner in Regular expressions and I want to check if a string variable satisfy a specified expression like this :

R|numeric_value|^value0^^^value1|value2|value_or_null|date_value

Note : The symbols (| and ^) are mandatory static characters and they are considered as Fields delimiters

any one help please!

Thanks in advance

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Saddam Meshaal
  • 532
  • 3
  • 13
  • 30
  • If you just want to check if a RegEx matches a pattern... have you searched how RegEx class works in C#? Give this a try https://stackoverflow.com/a/1775017/3563910 – Gonzo345 Mar 20 '19 at 11:17

1 Answers1

1

You can use online services like http://regexstorm.net/tester but for your learning. I recommend a T.D.D. approach with xUnit for example https://xunit.github.io/.

With something like that :

[Theory]
[InlineData("input_1", "pattern")]
[InlineData("input_2", "pattern")]
[InlineData("input_x", "pattern")]
public void ShouldMatch(string input, string pattern)
{
  try
  {
    var isMatch = Regex.IsMatch(input, pattern);
    Assert.True(isMatch);
  }
  catch (ArgumentException)
  {
    Assert.True(false);
  }
}

EDIT :

Thank you for your response, But how can the pattern be ?

  1. Read the documentation .Net Regular Expression Language - Quick Reference .
  2. Split your regex by logical OR/AND/NOR/NAND/etc operators .
  3. Use the Tdd cycle steps .
  4. Solve the first expression .
  5. Solve the second expression.
  6. Solve both expressions with your logical OR/AND/NOR/NAND/etc operators between first and second expression.
  7. Etc.

After this little exercise. You will better understand how to build patterns by yourself.