2

I have the following regex that works with the .NET regex engine (FYI, what this does is to parse command line arguments of the form name="value1,value2" name2 = value3 where the quotes are optional)

(?<name>[^=]+)=?((?<quoted>\""?)(?<value>(?(quoted)[^\""]+|[^,]+))\""?,?)

and want to use this in C++ 11. However, I understand that there are no named groups or conditions(? not entirely sure) in C++'s regex syntax.

I'm asking this question here because I haven't found any tools/web pages where I can easily test a regex and have it work in C++ 11 (whereas there are tools for almost all other platforms). A link to an online (or offline) C++ 11 compatible regex tester tool that can show me groups, subgroups and display helpful error messages would also be an acceptable answer.

PS: I understand that command line parsing is an exercise best suited to a parser but I have been using this simple regex long enough without any issues for most of my command-line tools that I am ok with any drawbacks it may have.

Ani
  • 10,826
  • 3
  • 27
  • 46

1 Answers1

0

The support for regex in C++11 is still sketchy, for example gcc will have good regex support only in version 4.9. You haven't specified what's your environment, but you can find details about what's supported and what's not in this question.

Your best bet is using the boost regex library - you should read Understanding Marked Sub-Expressions and Captures.

To make it a bit easier for you to test and experiment, as you requested, here's a ready environment that adapts the example from the boost article, with the right compilation flags g++-4.8 -O2 -Wall -pedantic -pthread -DBOOST_REGEX_MATCH_EXTRA main.cpp -lboost_regex set up: http://coliru.stacked-crooked.com/a/8950eb9c097b0db1

Community
  • 1
  • 1
mockinterface
  • 14,452
  • 5
  • 28
  • 49
  • This worked well for me. I would request people who find other (or better tools) to keep this answer updated. – Ani Jan 17 '14 at 02:01