Created
May 5, 2014 06:57
-
-
Save lihaoyi/dc63796497638d56fc2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/spray-util/src/main/scala/spray/util/pimps/PimpedRegex.scala | |
+++ b/spray-util/src/main/scala/spray/util/pimps/PimpedRegex.scala | |
@@ -20,12 +20,9 @@ import java.util.regex.Pattern | |
import scala.util.matching.Regex | |
class PimpedRegex(regex: Regex) { | |
def groupCount = { | |
try { | |
- val field = classOf[Pattern].getDeclaredField("capturingGroupCount") | |
- field.setAccessible(true) | |
- field.getInt(regex.pattern) - 1 | |
+ regex.pattern.matcher("").groupCount() | |
} catch { | |
case t: Throwable ⇒ | |
throw new RuntimeException("Could not determine regex group count: " + regex.pattern.pattern |
Author
lihaoyi
commented
Dec 2, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment