Why fid microsoft see it fit to change regex syntax, something that has been well used for 30+ years? RRS feed

  • Question

  • I have programmed in C for more than 30 years and now I am transitioning into C#. I ran into a brick wall when trying to code a RegEx parse search routine. It seems the RegEx syntax is not the same between C and C#. For example "^.\{20\}[2-4]" works for C but not for C#. Why,  why in the world would take something that's been  in use for so long and CHANGE IT??? I admit, I could have done something wrong to cause this, in which case, I apologize.

    Thursday, March 19, 2020 5:21 PM

All replies

  • Regular expressions are not bound by a programming language, perhaps you can include some test code with sample input and sample expected result.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, March 19, 2020 5:45 PM
  • Hi Bing H Bang,

    Thank you for posting here.

    There are two commonly used syntax for regular expressions, POSIX and Perl. Maybe the difference between these two standards caused this problem?

    Anyway, if you want to use regex in C#, please refer to the documentation provided by Microsoft.

    Regular Expression Language - Quick Reference

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, March 20, 2020 2:07 AM
  • Other prominent engines and languages currently use “{ }” and “( )” instead of “\{ \}” and “\( \)”, probably for simplification. I think that it is like a tacit standard.

    In order to use “\{ \}” and “\( \)” you can specify some special options. For example, in case of modern C++ std::regex class, you can select the “basic” or “grep” grammar.

    However, this does not seem available in case of .NET Regex class, where you simply write “{ }” and “( )”.

    What C library are you using in your code?

    • Edited by Viorel_MVP Friday, March 20, 2020 11:30 AM
    Friday, March 20, 2020 11:26 AM