Skip to content

Commit 41e99c7

Browse files
authored
Merge pull request #595 from jozic/regex-matches
2 parents a791e2d + 956249b commit 41e99c7

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ lazy val compat = new MultiScalaCrossProject(
8282
sharedSourceDir / "scala-2.11_2.12"
8383
}
8484
},
85-
versionPolicyIntention := Compatibility.BinaryAndSourceCompatible,
85+
versionPolicyIntention := Compatibility.BinaryCompatible,
8686
mimaBinaryIssueFilters ++= {
8787
import com.typesafe.tools.mima.core._
8888
import com.typesafe.tools.mima.core.ProblemFilters._
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.util.matching
14+
15+
package object compat {
16+
final implicit class RegexOps(val regex: Regex) extends AnyVal {
17+
18+
/** Returns whether this `Regex` matches the given character sequence.
19+
*
20+
* Like the extractor, this method takes anchoring into account.
21+
*
22+
* @param source The text to match against
23+
* @return true if and only if `source` matches this `Regex`.
24+
* @see [[Regex#unanchored]]
25+
* @example {{{"""\d+""".r matches "123" // returns true}}}
26+
*/
27+
def matches(source: CharSequence): Boolean = regex.pattern.matcher(source).matches()
28+
}
29+
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.util.matching
14+
15+
package object compat {
16+
type Regex = scala.util.matching.Regex
17+
val Regex = scala.util.matching.Regex
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package scala.util.matching.compat
14+
15+
import org.junit.Assert._
16+
import org.junit.Test
17+
18+
class RegexOpsTest {
19+
20+
@Test
21+
def testMatches(): Unit = {
22+
assertTrue(".*hello.*".r.matches("hey hello"))
23+
assertFalse(".*hello.*".r.matches("hey hop"))
24+
}
25+
26+
}

0 commit comments

Comments
 (0)