-4

What does this mean in regex?

(?s:.+?)

specifically

(?s

I've seen things like non capture groups (?:regex), lookaheads but this is the first time I see something like this, I got it from the MarkDownExtra parser definition lists part.

I was unable to find it on http://www.regular-expressions.info/ and Google because you can't physically google question marks, so I am asking here.

Also isn't .+? the same as .*?

aliteralmind
  • 19,847
  • 17
  • 77
  • 108
Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143
  • `.+` matches between 1 and unlimited times, `.*` matches between 0 and unlimited times. – admdrew Mar 28 '14 at 17:41
  • 2
    http://regex101.com/ is another pretty good site for testing/explaining regexes. You have answers already, but for the record it says ("match the remainder of the group with the following options: s modifier: single line. Dot matches newline characters"). – TessellatingHeckler Mar 28 '14 at 17:42
  • 1
    http://www.regular-expressions.info/modifiers.html – aliteralmind Mar 28 '14 at 17:42
  • 1
    @aliteralmind Thank you, I don't know how I missed that, I guess I just didn't imagine it being a modifier at all. – Timo Huovinen Mar 28 '14 at 17:52
  • `.+` one or more greedy, `.+?` one or more lazy, didn't know this. – Timo Huovinen Mar 28 '14 at 18:40
  • Consider [RegexBuddy](http://regexbuddy.com) if you're on Windows. It's a great application for analyzing regexes. For constructing regexes, they also have [RegexMagic](http://www.regexmagic.com/), which I've not used. – aliteralmind Mar 28 '14 at 18:43

2 Answers2

3

It is an inline modifier:

(?s)

That was extended so that only the part within the group is affected. This means that the . within the group will be on 'dotall' mode (or match newlines too).

Jerry
  • 70,495
  • 13
  • 100
  • 144
2

Using this link You can get explanation of your regex.

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  (?s)                     set flags for this block (with . matching
                           \n) (case-sensitive) (with ^ and $
                           matching normally) (matching whitespace
                           and # normally)
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85