Question about regex with negated character class

Roger L Costello <>
Mon, 25 Apr 2022 12:48:43 +0000

          From comp.compilers

Related articles
Question about regex with negated character class (Roger L Costello) (2022-04-25)
Re: Question about regex with negated character class (Kaz Kylheku) (2022-04-25)
| List of all articles for this month |

From: Roger L Costello <>
Newsgroups: comp.compilers
Date: Mon, 25 Apr 2022 12:48:43 +0000
Organization: Compilers Central
Injection-Info:; posting-host=""; logging-data="57597"; mail-complaints-to=""
Keywords: lex, question, comment
Posted-Date: 25 Apr 2022 12:33:08 EDT
Accept-Language: en-US
Content-Language: en-US

Hi Folks,

On page 12 of the Flex specification it says this:

"A negated character class such as [^A-Z] will match a newline
unless \n (or an equivalent escape sequence) is one of the characters
explicitly present
in the negated character class (e.g., [^A-Z\n]). This is unlike how many other
expression tools treat negated character classes ..."

Is that last sentence true? Does Flex behaves differently from other regex
engines, with regard to negated character class?

I just tested the [^A-Z] regex at ( and every regex
engine on that web page matches a string containing a newline. In other words,
Flex behaves just like all the other regex engines. I conclude that that last
sentence in the Flex manual is not correct. Do you agree?

[It may have been true 30 years ago but they all match \n in a pattern
now. On the other hand, grep won't match a newline because it does the
matching one line at a time. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.