0

I'm new to regex expressions and with the help of some regex tester i've written the following regex expression:

Match m = Regex.Match(readText, @"/\[[A-Z][A-Z]\-\d\d\d\d\d\-\-\]/g");

Test values:

[CP-00000--#G100] -No match

[CP-00000--] -Match

[CP-00099--] -Match

[CP-00000--.base#G100] -No match

If I test this in the online Regex tester this expression matches all the cases I want it to match. But whenever I test this in my program i doesnt find any machtes.

T Jasinski
  • 113
  • 2
  • 12
  • `Regex.Matches(readText, @"\[[A-Z]{2}-\d{5}--]")` – Wiktor Stribiżew Oct 24 '19 at 10:06
  • 1
    FYI C# regexes don't use switches - so the `/g` at the end of your expression is interpreted as part of the regex, so it won't match. – stuartd Oct 24 '19 at 10:08
  • @WiktorStribiżew Thank you that worked for me. Can you explain why my question is a duplicate? I agree that the question about regex expressions have been asked quite a lot. But because I've my specific expression doesn't that make the question unique? Just wondering in case i need to ask a question on here again. – T Jasinski Oct 24 '19 at 12:08
  • 1
    1) You should not use regex delimiters with flags - regex literals - in C# when defining regex (Dupe #1). 2) To match multiple occurrences, use `Regex.Matches`, not `Regex.Match` (Dupe #2). – Wiktor Stribiżew Oct 24 '19 at 12:11

0 Answers0