Ahmed_Mostafa's blog

By Ahmed_Mostafa, history, 7 years ago, In English

I was trying to solve a problem using c++ regex class but a runtime error occurred. I printed the exception and it was : "Number of NFA states exceeds limit. Please use shorter regex string, or use smaller brace expression, or make larger." (submission : http://mirror.codeforces.com/contest/832/submission/29048936)

the macro _GLIBCXX_REGEX_STATE_LIMIT is defined here: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/regex_automaton.h

as #define _GLIBCXX_REGEX_STATE_LIMIT 100000

For the specific problem I was trying to solve the pattern string I had to construct can exceed 100000 chars and so maybe when it gets converted to a NFA it will need more states,of course this is an internal header file and we don't have access to it so I can't include it and undefine the macro and redefine it with another limit.

Does anyone know how to change this limit ? the exception message clearly said "or make _GLIBCXX_REGEX_STATE_LIMIT larger." so there should be a way to change that limit.

  • Vote: I like it
  • -2
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

It says

#ifndef _GLIBCXX_REGEX_STATE_LIMIT
#define _GLIBCXX_REGEX_STATE_LIMIT 100000
#endif

So just define the macro at the top of your program.