Home > database >  C Regex "Parenthesis is not closed." Error
C Regex "Parenthesis is not closed." Error

Time:02-26

In a game I'm making, I'm using a Regex expression to be able to parse in level data from a file. To test this, I'm trying to use the Regex expression (?<=(LEVEL_TYPE:\s))(\w |[ -]*\d ) to try and get the level type data in the file which is formatted like LEVEL_TYPE: UNDERWATER

This is my code:

   std::string RegexPattern("(?<=(LEVEL_TYPE:\\s))(\\w |[ -]*\\d )");
   std::string target = "LEVEL_TYPE: UNDERWATER";
   std::regex reg(RegexPattern);

Without even using the regex_match method, the program throws an error why I try to run the code. When I try to run it, it throws the error:

terminate called after throwing an instance of 'std::regex_error'
  what():  Parenthesis is not closed.

I'm trying to compile on MinGW on Windows, GCC version 6.3.0

CodePudding user response:

I can't see a reason for the lookbehind. Isn't this enough?

std::string RegexPattern("(LEVEL_TYPE:\\s)(\\w |[ -]*\\d )");
  • Related