diff options
author | Daniel C. Sobral <dcsobral@gmail.com> | 2012-01-25 13:30:40 -0200 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-03-23 06:57:00 -0700 |
commit | e3dec9f006ac2631281fb936c4ca206daa8fda5d (patch) | |
tree | 4c2bb8efc68199fde4d51a58a20f5ded595efeb5 /src/library/scala/collection/immutable/StringLike.scala | |
parent | 8f42361d71d11e9522052dcb5d9be020df7e5cc5 (diff) | |
download | scala-e3dec9f006ac2631281fb936c4ca206daa8fda5d.tar.gz scala-e3dec9f006ac2631281fb936c4ca206daa8fda5d.tar.bz2 scala-e3dec9f006ac2631281fb936c4ca206daa8fda5d.zip |
Regex improvements
This adds findAllMatchIn to Regex to mirror other similar methods.
It also overloads StringLike's "r", adding a version that accepts
group names.
It includes test cases for both methods.
Closes SI-2460.
Diffstat (limited to 'src/library/scala/collection/immutable/StringLike.scala')
-rw-r--r-- | src/library/scala/collection/immutable/StringLike.scala | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index f9697565de..fc4e7bf0a8 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -207,9 +207,20 @@ self => /** You can follow a string with `.r`, turning it into a `Regex`. E.g. * - * """A\w*""".r is the regular expression for identifiers starting with `A`. + * `"""A\w*""".r` is the regular expression for identifiers starting with `A`. */ - def r: Regex = new Regex(toString) + def r: Regex = r() + + /** You can follow a string with `.r(g1, ... , gn)`, turning it into a `Regex`, + * with group names g1 through gn. + * + * `"""(\d\d)-(\d\d)-(\d\d\d\d)""".r("month", "day", "year")` matches dates + * and provides its subcomponents through groups named "month", "day" and + * "year". + * + * @param groupNames The names of the groups in the pattern, in the order they appear. + */ + def r(groupNames: String*): Regex = new Regex(toString, groupNames: _*) def toBoolean: Boolean = parseBoolean(toString) def toByte: Byte = java.lang.Byte.parseByte(toString) |