TR1 regex: capture groups?

I am using TR1 Regular Exions (for VS2010) and I am trying to search for a specific template for a group called "name" and another template for a group called "value". I think what I want is called a capture group, but I'm not sure if this is the correct terminology. I want to assign matches to the pattern "[^: \ r \ n] +): \ s" in the list of matches called "name", and matches to the pattern "[^ \ r \ n] +) \ r \ n) +" in a list of matches called "value".

The regex pattern that I still have is

string pattern = "((?<name>[^:\r\n]+):\s(?<value>[^\r\n]+)\r\n)+"; 

But the TREREX regular expression header continues to throw an exception when the program starts. What is wrong with the syntax of the template that I have? Can someone show an example of a template that will do what I'm trying to execute?

Also, how could you include a substring in a template so that it matches, but doesn’t actually include that substring in the results? For example, I want to combine all the lines of a template

 "http://[[:alpha:]]\r\n" 

but I don’t want to include the substring "http: //" in the returned results of matches.

+3
source share
1 answer

C ++ TR1 and C ++ 11 regular expression regular expressions do not support named capture groups. You will need to perform unnamed capture groups.

Also, make sure that you do not run screening problems. You will have to avoid some characters twice: one in order to be in a C ++ string, and the other for regular expression. The pattern (([^:\r\n]+):\s\s([^\r\n]+)\r\n)+ can be written as a C ++ string literal as follows:

 "([^:\\r\\n]+:\\s\\s([^\\r\\n]+)\\r\\n)+" // or in C++11 R"xxx(([^:\r\n]+:\s\s([^\r\n]+)\r\n)+)xxx" 

Lookbehind are not supported. You will have to get around this limitation using capture groups: use the pattern (http://)([[:alpha:]]\r\n) and take only the second capture group.

+7
source

Source: https://habr.com/ru/post/946368/


All Articles