package com.aura.scala.day01

import scala.util.matching.Regex

object regularExpressionPatterns {
def main(args: Array[String]): Unit = {
// example 1
// .r 方法可便任意字符串变成一个正则表达式
val numberPatter: Regex = "[0-9]".r
numberPatter.findFirstMatchIn("dsafasdfasfasfas") match {
case Some(_) => println("Password OK")
case None => println("Password must contain a number")
}
// example 2
val KeyValPattern: Regex = "([0-9A-Za-z-#() ]+):([0-9A-Za-z-#() ]+)".r
val input: String =
"""
|background-color: #A03300;
|background-image: url(img/header100.png);
|background-position: top center;
|background-repeat: repeat-x;
|background-size: 2160px 108px
|margin: ;
|height: 108px;
|width: %;
""".stripMargin
for( patternMath <- KeyValPattern.findAllMatchIn(input))
println(s"key:${patternMath.group(1)} value:${patternMath.group(2)}")
}
}

output:

"D:\Program Files\Java\jdk1.8.0_201\bin\java.exe" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar=8599:D:\Program Files\JetBrains\IntelliJ IDEA 2019.1.3\bin" -Dfile.encoding=UTF- -classpath "D:\Program Files\Java\jdk1.8.0_201\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_201\jre\lib\rt.jar;C:\Users\admin\IdeaProjects\ScalaDay\out\production\ScalaDay;C:\Program Files (x86)\scala\lib\scala-actors-2.11.0.jar;C:\Program Files (x86)\scala\lib\scala-actors-migration_2.11-1.1.0.jar;C:\Program Files (x86)\scala\lib\scala-library.jar;C:\Program Files (x86)\scala\lib\scala-parser-combinators_2.11-1.0.4.jar;C:\Program Files (x86)\scala\lib\scala-reflect.jar;C:\Program Files (x86)\scala\lib\scala-swing_2.11-1.0.2.jar;C:\Program Files (x86)\scala\lib\scala-xml_2.11-1.0.4.jar" com.aura.scala.day01.regularExpressionPatterns
Password must contain a number
key:background-color value: #A03300
key:background-image value: url(img
key:background-position value: top center
key:background-repeat value: repeat-x
key:background-size value: 2160px 108px
key:margin value:
key:height value: 108px
key:width value:

learning scala regular expression patterns的更多相关文章

  1. Regular Expression Patterns

    Regular Expression Patterns Following lists the regular expression syntax that is available in Pytho ...

  2. JavaScript Patterns 3.6 Regular Expression Literal

    1. Using the new RegExp() constructor // constructor var re = new RegExp("\\\\", "gm& ...

  3. python learning Regular Expression.py

    # 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念.正则表达式通常被用来检索.替换那些符合某个模式(规 ...

  4. Python中的正则表达式regular expression

    1 match = re.search(pat,str)  If the search is successful, search() returns a match object or None o ...

  5. LeetCode (10): Regular Expression Matching [HARD]

    https://leetcode.com/problems/regular-expression-matching/ [描述] Implement regular expression matchin ...

  6. Regular Expression Syntax

    python的正则表达式 正则表达式的概念 正则表达式是对字符串操作的一种逻辑公式,就是用事先定义好的一些特定字符.及这些特定字符的组合,组成一个"规则字符串",这个"规 ...

  7. 正则表达式-使用说明Regular Expression How To (Perl, Python, etc)

    notepad++ wiki about regular expression 正则表达式-使用说明Regular Expression How To (Perl, Python, etc) http ...

  8. C#中【正则表达式regular expression】相关的知识

    Regex System.Text.RegularExpressions.Regex      regex应该是regular expression的缩写 https://msdn.microsoft ...

  9. [LeetCode] Regular Expression Matching 正则表达式匹配

    Implement regular expression matching with support for '.' and '*'. '.' Matches any single character ...

随机推荐

  1. PAT甲级题分类汇编——计算

    本文为PAT甲级分类汇编系列文章. 计算类,指以数学运算为主或为背景的题. 题号 标题 分数 大意 1058 A+B in Hogwarts 20 特殊进制加法 1059 Prime Factors ...

  2. AVR单片机教程——EasyElectronics Library v1.0手册

    更新:EasyElectronics Library v1.1手册 索引: bit.h delay.h pin.h tone.h pwm.h uart.h adc.h led.h rgbw.h seg ...

  3. Oracle 11g xe版本---总结1

    一.创建用户和授予权限 1.1 环境: Oracle 11g xe 第三方图形客户端: PLSQL Windows 10 必须登录 HR 用户,下面的查询会使用到 HR 中的表. 1.2 SQL 语句 ...

  4. VMware Workstation Pro 15 序列号

    VMware Workstation Pro 15 序列号: GA70H-8TYE2-H886P-04YZC-YVA84 YG5H2-ANZ0H-M8ERY-TXZZZ-YKRV8 UG5J2-0ME ...

  5. SVN_03绿色版

    1.首先备份当前安装visualSVN文件的bin目录,万一出错还能反个水.一般默认安装路径是C:\Program Files(x86)VisualSVN\bin 2.然后运行ildasm,Windo ...

  6. SQL Server2008存储过程中函数的用法(举例)

    USE   数据库 GO SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO CREATE   function  函数名称 (@EmpID   nvarcha ...

  7. entity-framework-core – 实体框架核心RC2表名称复数

    参考地址:https://docs.microsoft.com/zh-cn/ef/core/modeling/relational/tables http://www.voidcn.com/artic ...

  8. R_数据操作_初级_03

    数据的输入:详见(http://cran.r-project.org/doc/manuals/R-data.pdf下载的R Data Import/Export手册②) 1.键盘输入:使用edit() ...

  9. 三种JS截取字符串方法

    JS提供三个截取字符串的方法,分别是:slice(),substring()和substr(),它们都可以接受一个或两个参数: var stmp = "rcinn.cn"; 使用一 ...

  10. SDL图解

    1.什么是SDL 2.为什么要用SDL 3.SDL由哪几个阶段组成 用于规范公司web应用开发流程:安全需求分析.代码检查.安全测试... 4.微软的SDL实施流程