-2
/(?:(?:^|.*;)\s*key\s*\=\s*([^;]*).*$)|^.*$/

I got this RegExp which can get the key in cookie ,but I don't know what

(?:^|.*) mean , I mean what ?: mean in javascript

Narendrasingh Sisodia
  • 19,948
  • 5
  • 40
  • 50
Mofei Zhu
  • 179
  • 2
  • 9

2 Answers2

2

() would define a capturing group. (?:) will make it non-capturing.

Reference - What does this regex mean?

Community
  • 1
  • 1
ndnenkov
  • 33,260
  • 9
  • 67
  • 97
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – SuperBiasedMan Aug 28 '15 at 09:35
  • @SuperBiasedMan, I would disagree. When a question is *what is x*, the answer *it's like y, but with this difference* should be more than satisfactory given knowing what *y* is. – ndnenkov Aug 28 '15 at 09:41
  • *"given knowing what y is"* - If someone doesn't know the difference between the syntax it's quite possible they wont know the terms either. There's little reason to not include explanations of those terms. – SuperBiasedMan Aug 28 '15 at 09:44
  • @SuperBiasedMan, read OP's question. He is comfortable with ordinary brackets, he is just confused about the `?:` part. – ndnenkov Aug 28 '15 at 09:46
  • OP is but others may not be when searching this question. – SuperBiasedMan Aug 28 '15 at 09:53
  • @SuperBiasedMan, I'm sure others that search for *what is `?:`?* wouldn't want to see explanation of things like `()`. If they want to learn that, they would search for `()` instead, or even better, they should take 15 mins to read about regex basics. – ndnenkov Aug 28 '15 at 09:58
  • @ndn please check if my edit is ok. If not, undo! – Jonny 5 Aug 28 '15 at 10:52
  • @Jonny5, I appreciate your change. Thank you! – ndnenkov Aug 28 '15 at 11:29
2

It is called Non-Capturing Groups: (?: … )

For instance (?:Mofei|Zhu) matches Mofei or Zhu—but the name is not captured.

Narendrasingh Sisodia
  • 19,948
  • 5
  • 40
  • 50