Matching Compiler Flags using regex
I wish to generate preprocessor and assembly files from a c++ source file using a c++ program which will invoke the compiler. Now, for some codes, additional flags may be required like -std=c++17, -masm=intel, etc. I can take the user input for such flags, but at the same time, I wish to prevent the user from entering flags that may not be relevant in this case, as the program is not supposed to generate executable files or rename the generated .s and .ii files. The flags that I can allow the user to type are: -masm=<arg>, -std=c++<ver>, -S, -l<lib> and -save-temps For this, I thought of using the following regex : regex("((-std=c\\+\\+(03|11|14|17|20|0x|1y|1z|2a) )?(-l\\w+ )?(-masm=\\w+ )?)-S -save-temps"); However, if I change the order of the flags, like "-std=c++17 -S -save-temps" to "-S -save-temps -std=c++17", the regex fails to match, which is expected. But the compiler will treat the two strings as equivalent, and that is what I want to achieve. How can I create the regex that matches the flags in the desired way? Is there a way or am I forced to keep the strings in order, by splitting them into individual flags, and sorting them in order?