在正则表达式中不是OR

时间:2017-11-01 07:05:02

标签: regex regex-negation

我想制作一个(nginx)v1规则来过滤除了这些词之外的所有内容:key1anotherkey2#include <stdio.h> #include <stdlib.h> #include <string.h> struct time { int hour; int minute; char am_pm [3]; char (*standard_time)(struct time *self); }; char standard_time_format(struct time *self) { char standard_format[8], conversion[3]; int length; length = snprintf(NULL, 0, "%d", self->hour); snprintf(conversion, length + 1, "%d", self->hour); strcpy(standard_format, conversion); strcat(standard_format, ":"); length = snprintf(NULL, 0, "%d", self->minute); snprintf(conversion, length + 1, "%d", self->minute); strcat(standard_format, conversion); strcat(standard_format, self->am_pm); return(standard_format); } int main() { struct time start; char standard_format[8]; start.hour = 2; start.minute = 34; strcpy(start.am_pm, "am"); start.standard_time = standard_time_format; strcpy(standard_format, start.standard_time(&start)); printf("%s\n", standard_format); return 0; } 即可。有谁知道如何表达?

2 个答案:

答案 0 :(得分:1)

你可以使用正则表达式

\b(?!v1|key1|another|key2)\w+\b

检查regex101 demo

答案 1 :(得分:0)

以下正则表达式应该可以解决这个问题

/\b(?!v1|key1|key2|another)\b\S+/g

取自implementation