I got into a discussion with my co-worker on whether there can be only one correct regular expression for every pattern. I think that two correct regular expressions can occur. Can a pattern be associated with two different, correct regular expressions? Are [^span] and (?!span) the same thing?
Asked
Active
Viewed 46 times
-7
-
2`[^]`: negated set. `(?!)`: negative lookahead – Maximilian Burszley Apr 04 '18 at 01:44
-
1They do very different things. They're not comparable at all. One is an car, the other a carrot. They're not anywhere near the same thing even though they both start with the same three letters. – Ken White Apr 04 '18 at 01:49
-
Possible duplicate of [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – Sebastian Simon Apr 04 '18 at 05:02
1 Answers
3
(?!phrase)
is negative lookahead: from the current point, the following phrase must not be "phrase".
[^span]
is much different - it matches any single character that is not s
, p
, a
, or n
.

CertainPerformance
- 356,069
- 52
- 309
- 320