1

the regex i am using is for an implementation of preprocessor, in flex. This preprocessor is kindof simple. It obeys following rules:

  1. the preprocessor directive starts with #define followed by identifier in capital letters
  2. the use-case of preprocessor identifier begins with a # sign.

for example:

#define CONSTANT 100
//...
int x = #CONSTANT;

so first thing i did was

#define {
           //store the identifier following #define in a lookup table 
           //do the relevant error checking 
        }
NO_POUND_DEFINE {
                  //The string should begin with a '#' sign but not with `#define`
                  //check if the string following '#' is upper case or not
                  //if in upper case do the lookup otherwise throw an error
                }
Jacob Schoen
  • 14,034
  • 15
  • 82
  • 102
A. K.
  • 34,395
  • 15
  • 52
  • 89

2 Answers2

2
var regexp = /^((?!#define).)*$/;

Maybe you want to take a look at this: regular-expression-to-match-string-not-containing-a-word

Community
  • 1
  • 1
user278064
  • 9,982
  • 1
  • 33
  • 46
1

^#([^d]|d[^e]|de[^f]|def[^i]|defi[^n]|defin[^e]).* The string starts with a '#' not followed by a 'd' or followed by a 'd' but not followed by an 'e' etc.

aalku
  • 2,860
  • 2
  • 23
  • 44