A. K.
A. K.

Reputation: 38126

regex for all text beginning with "#" but not with #define

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
                }

Upvotes: 1

Views: 309

Answers (2)

user278064
user278064

Reputation: 10170

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

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

Upvotes: 2

aalku
aalku

Reputation: 2878

^#([^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.

Upvotes: 1

Related Questions