本文整理汇总了Scala中scala.util.matching.Regex.Match类的典型用法代码示例。如果您正苦于以下问题:Scala Match类的具体用法?Scala Match怎么用?Scala Match使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Match类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: FlightPassengerSplitsReportingService
//设置package包名称以及导入依赖的类
package passengersplits.query
import akka.pattern.AskableActorRef
import akka.util.Timeout
import org.joda.time.DateTime
import passengersplits.core
import passengersplits.core.PassengerInfoRouterActor._
import services.SDate.implicits._
import drt.shared.SDateLike
import scala.concurrent.{ExecutionContext, Future}
import scala.util.matching.Regex.Match
object FlightPassengerSplitsReportingService {
def parseUrlDateTime(notQuiteIsoDatetime: String) = {
val dateTimeRe = """(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)""".r
val matches: Option[Match] = dateTimeRe.findFirstMatchIn(notQuiteIsoDatetime)
matches match {
case Some(reMatch) =>
val isoDt = s"${reMatch.group(1)}-${reMatch.group(2)}-${reMatch.group(3)}T${reMatch.group(4)}:${reMatch.group(5)}:00"
DateTime.parse(isoDt)
case None => None
}
}
def calculateSplits(aggregator: AskableActorRef)
(destPort: String, terminalName: String, flightCode: String, arrivalTime: SDateLike)(implicit timeout: Timeout, ec: ExecutionContext) = {
import scala.concurrent.duration._
getCarrierCodeAndFlightNumber(flightCode) match {
case Some((cc, fn)) => aggregator.ask(ReportVoyagePaxSplit(destPort, cc, fn, arrivalTime))(Timeout(500 milliseconds))
case None => Future.failed(new Exception(s"couldn't get carrier and voyage number from $flightCode"))
}
}
val flightCodeRe = """(\w{2})(\d{1,5})""".r("carrierCode", "voyageNumber")
def getCarrierCodeAndFlightNumber(flightCode: String) = {
flightCodeRe.findFirstMatchIn(flightCode) match {
case Some(matches) => Some((matches.group("carrierCode"), matches.group("voyageNumber")))
case None => None
}
}
}
开发者ID:UKHomeOffice,项目名称:drt-scalajs-spa-exploration,代码行数:46,代码来源:FlightPassengerSplitsReportingService.scala
示例2: StringParser
//设置package包名称以及导入依赖的类
package dbpedia.dataparsers
import dbpedia.dataparsers.util.wikiparser._
import scala.util.matching.Regex.Match
object StringParser extends DataParser
{
private val smallTagRegex = """<small[^>]*>\(?(.*?)\)?<\/small>""".r
private val tagRegex = """\<.*?\>""".r
override def parse(node : Node) : Option[String] =
{
//Build text from node
val sb = new StringBuilder()
nodeToString(node, sb)
//Clean text
var text = sb.toString()
// Replace text in <small></small> tags with an "equivalent" string representation
// Simply extracting the content puts this data at the same level as other text appearing
// in the node, which might not be the editor's semantics
text = smallTagRegex.replaceAllIn(text, (m: Match) => if (m.group(1).nonEmpty) "($1)" else "")
text = tagRegex.replaceAllIn(text, "") //strip tags
text = WikiUtil.removeWikiEmphasis(text)
text = text.replace(" ", " ")//TODO decode all html entities here
text = text.trim
if(text.isEmpty)
{
None
}
else
{
Some(text)
}
}
private def nodeToString(node : Node, sb : StringBuilder)
{
node match
{
case TextNode(text, _) => sb.append(text)
case _ : TemplateNode | _ : TableNode => //ignore
case _ => node.children.foreach(child => nodeToString(child, sb))
}
}
}
示例3: replaceInVariablesMap
//设置package包名称以及导入依赖的类
package ca.andrewmcburney.skeleton.files
// Skeleton imports
import ca.andrewmcburney.skeleton.Globals._
import ca.andrewmcburney.skeleton.Logger
import ca.andrewmcburney.skeleton.files.SkeletonPath._
// Other imports
import better.files._
import java.nio.file.{Path, Files}
import scala.util.matching.Regex.Match
private def replaceInVariablesMap(m: Match, fileVars: VarMap): String = {
val key = variable(m.group(1))
val fileOperations = operations(m.group(1))
if (fileVars.contains(key) && !fileOperations.isEmpty) {
FileOperations.operate(fileVars(key), fileOperations)
} else if (fileVars.contains(key)) {
fileVars(key)
} else {
m.toString
}
}
}
示例4: TimeParser
//设置package包名称以及导入依赖的类
package performanceanalysis
import java.time.LocalTime
import scala.util.Try
import scala.util.matching.Regex.Match
class TimeParser(shift: Int) {
private val iHour = shift + 1
private val iMin = shift + 2
private val iSec = shift + 3
private val iNano = iSec + 1
private def nanoOption(s: String): Option[String] = {
val nanoTry = Try(Option(s))
nanoTry.toOption.flatten
}
def parse(m: Match): LocalTime = {
val hour = m.group(iHour).toInt
val min = m.group(iMin).toInt
val sec = m.group(iSec).toInt
val nano = nanoOption(m.group(iNano)) match {
case None => 0
case Some(".") => 0
case Some(s) => (s.toDouble * 1000000000).toInt
}
LocalTime.of(hour, min, sec, nano)
}
}
示例5: regexMatchedParser
//设置package包名称以及导入依赖的类
package com.github.kczulko.isc.dhcp.parsers
import scala.util.matching.Regex
import scala.util.matching.Regex.Match
import scala.util.parsing.combinator.RegexParsers
trait RegexMatchedParser extends RegexParsers {
def regexMatchedParser(r: Regex): Parser[Match] = (in: Input) => {
val source = in.source
val offset = in.offset
val start = handleWhiteSpace(source, offset)
r findPrefixMatchOf source.subSequence(start, source.length) match {
case Some(matched) =>
Success(matched, in.drop(start + matched.end - offset))
case None =>
Failure(
s"string matching regex `$r' expected but `${in.first}' found",
in.drop(start - offset)
)
}
}
}
示例6: CharacterCounter
//设置package包名称以及导入依赖的类
package exam
import text.{StringNone, StringOption, StringSome}
import scala.util.matching.Regex.Match
object CharacterCounter {
def count(text: StringOption): Int = {
text.codePointCount - surplusForNumberSequence(text)
}
private def surplusForNumberSequence(text: StringOption): Int = {
text match {
case StringSome(t) =>
var count: Int = 0
"[0-9]{2,}".r.findAllMatchIn(t) foreach {
m: Match =>
count += m.group(0).length
}
(count + 1) / 2
case StringNone => 0
}
}
}
示例7: JapaneseLengthCounter
//设置package包名称以及导入依赖的类
package us.feliscat.exam.ja
import us.feliscat.exam.MultiLingualLengthCounter
import us.feliscat.m17n.Japanese
import us.feliscat.text.{StringNone, StringOption, StringSome}
import scala.util.matching.Regex.Match
object JapaneseLengthCounter extends MultiLingualLengthCounter with Japanese {
override def count(text: StringOption): Int = {
text.codePointCount - surplusForNumberSequence(text)
}
private def surplusForNumberSequence(text: StringOption): Int = {
text match {
case StringSome(t) =>
var count: Int = 0
"[0-9]{2,}".r.findAllMatchIn(t) foreach {
m: Match =>
count += m.group(0).length
}
(count + 1) / 2
case StringNone => 0
}
}
}
示例8: TestHelper
//设置package包名称以及导入依赖的类
package org.quicli.testbase
import scala.collection.mutable.{StringBuilder, Map => MMap}
import scala.util.matching.Regex.Match
object TestHelper {
val quotesRegex = """[\"\'].*?[\"\']""".r
def toArgSeq(line: String): Seq[String] = {
if (line.isEmpty) return Seq.empty
val replacements: MMap[String, String] = MMap.empty
val cl = new StringBuilder(line)
var maybeQuoteMatch: Option[Match] = quotesRegex.findFirstMatchIn(cl)
while (maybeQuoteMatch.isDefined) {
val qm: Match = maybeQuoteMatch.get
val quote: String = qm.toString()
val replacement: String = s"%q${replacements.size + 1}"
cl.replace(qm.start, qm.end, replacement)
replacements += (replacement -> quote)
maybeQuoteMatch = quotesRegex.findFirstMatchIn(cl)
}
cl.toString.split("\\s+").map { arg =>
replacements.foldLeft(arg) {
case (result, (r, o)) => result.replace(r, o)
}
}
}
}
示例9: StringHelper
//设置package包名称以及导入依赖的类
package org.quicli.utils.string
import scala.collection.mutable.{Map => MMap}
import scala.util.matching.Regex
import scala.util.matching.Regex.Match
object StringHelper {
def matches(str: String, regex: Regex): Boolean = {
regex.pattern.matcher(str).matches()
}
def quote(str: String, c: Char = '"'): String = {
val sb = new StringBuilder(str)
val cStr = s"$c"
if (!sb.startsWith(cStr)) sb.insert(0, c)
if (!sb.endsWith(cStr)) sb.append(c)
sb.toString()
}
val quotesRegex = """[\"\'].*?[\"\']""".r
def tokenize(line: String): Seq[String] = {
if (line.isEmpty) return Seq.empty
val replacements: MMap[String, String] = MMap.empty
val cl = new StringBuilder(line)
var maybeQuoteMatch: Option[Match] = quotesRegex.findFirstMatchIn(cl)
while (maybeQuoteMatch.isDefined) {
val qm: Match = maybeQuoteMatch.get
val quote: String = qm.toString()
val replacement: String = s"%q${replacements.size + 1}"
cl.replace(qm.start, qm.end, replacement)
replacements += (replacement -> quote)
maybeQuoteMatch = quotesRegex.findFirstMatchIn(cl)
}
cl.toString.split("\\s+").map { arg =>
replacements.foldLeft(arg) {
case (result, (r, o)) => result.replace(r, o)
}
}
}
}