# Help understand regex documentation

**URL:** <https://users.scala-lang.org/t/help-understand-regex-documentation/6386>\
**Category:** Question\
**Created:** [July 20, 2020, 9:56am UTC](https://users.scala-lang.org/t/help-understand-regex-documentation/6386 "2020-07-20T09:56:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimka](https://users.scala-lang.org/user_avatar/users.scala-lang.org/jimka/32/646_2.png) [@jimka](https://users.scala-lang.org/u/jimka)\
**Post date:** [July 20, 2020, 9:56am UTC](https://users.scala-lang.org/t/help-understand-regex-documentation/6386/1 "2020-07-20T09:56:28Z")

</div>

I’m looking at the 2.12 [documentation here](https://www.scala-lang.org/api/2.12.1/scala/util/matching/Regex.html):  
but I don’t understand the syntax of the pattern matching.

What do the parens in `case docSpree()` mean?

 ![Screenshot 2020-07-20 at 11.54.38](https://users.scala-lang.org/uploads/default/original/2X/5/56b2de7a8bd6a6ee98b6dd6cdac64231eaeaa6e2.png)

---

<div class="post-metadata">

**Author:** ![crater2150](https://users.scala-lang.org/user_avatar/users.scala-lang.org/crater2150/32/1011_2.png) [@crater2150](https://users.scala-lang.org/u/crater2150)\
**Post date:** [July 20, 2020, 11:07am UTC](https://users.scala-lang.org/t/help-understand-regex-documentation/6386/2 "2020-07-20T11:07:09Z")

</div>

In the examples further up in the documentation, you can see that you can add variables here that will be filled with match groups (using the regex’s `unapplySeq` method).

But even if you don’t have match groups, the parentheses are required, because without them, Scala would interpret the name `docSpree` as a pattern variable, shadowing the original regex variable. That way, the first case would always match, containing the string you wanted to match against in that variable.

See the differing results:

```auto
// with parens: unapplySeq method of docSpree regex
@ val docView = date.replaceAllIn(dates, _ match {
    case docSpree() => "Historic doc spree!"
    case _ => "Something else happened"
  })
docView: String = "Important dates in history: Something else happened, Something else happened, Something else happened, Historic doc spree!"

// without parens: free pattern variable, matches always
@ val docView = date.replaceAllIn(dates, _ match {
    case docSpree => "Historic doc spree!"
    case _ => "Something else happened"
  })
docView: String = "Important dates in history: Historic doc spree!, Historic doc spree!, Historic doc spree!, Historic doc spree!"

```
