-7

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?

Robert Columbia
  • 6,012
  • 14
  • 28
  • 36
c_taihei
  • 13
  • 2
  • 2
    `[^]`: negated set. `(?!)`: negative lookahead – Maximilian Burszley Apr 04 '18 at 01:44
  • 1
    They 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 Answers1

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
  • 260,466
  • 31
  • 181
  • 209