-1

Imagine a string "Hello World".

The regular expression for that is "Hello World".

In my regular expression class, I was told that a complement of a regular expression is a regular expression.

Say I want to check that a string doesn't contain Hello World. How do I do so?

I can do that for one character

[^a] for example will match anything that's not the letter a

How to do so for longer strings?

What's the equivalent of ^ for a string with length more than 1

Note: the other questions is not really a match. In fact, one of the answer says that regular expression cannot really do this. Academically speaking academic regular expression CAN do this. It's complement.

I don't look for a look around. I look for complement.

For example. Say I am parsing html. Say I want to match the content of table. I want to match something between contentsome other table

Basically a pattern would be (not )

Now how would I do (not )?

user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

0
^((?!Hello World).)*$

This regex will match any string, or line without a line break, not containing the sub string 'Hello World'.