learning scala regular expression patterns

时间:2022-06-30 08:11:04
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&period;6 Regular Expression Literal

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

  3. python learning Regular Expression&period;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 &lpar;10&rpar;&colon; Regular Expression Matching &lbrack;HARD&rsqb;

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

  6. Regular Expression Syntax

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

  7. 正则表达式-使用说明Regular Expression How To &lpar;Perl&comma; Python&comma; etc&rpar;

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

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

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

  9. &lbrack;LeetCode&rsqb; Regular Expression Matching 正则表达式匹配

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

随机推荐

  1. 第 22 章 CSS3 渐变效果

    学习要点: 1.线性渐变 2.径向渐变 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 背景渐变功能,主要有两种渐变方式:线性渐变和径向(放射性)渐变. 一.线性渐变 CSS3 提供了 li ...

  2. linux 开机启动设置

    操作系统:Ubuntu12.04硬件环境:HP CQ45        当用户使用sudo apt-get install安装完apache和mysql之后,这些服务默认是开机启动的,但是有的时候需要 ...

  3. 时间函数 time&period;h 详解

    C++对时间的操作也有许多值得大家注意的地方.最近,在技术群中有很多网友也多次问到过C++语言中对时间的操作.获取和显示等等的问题.下面,在这篇文章中,笔者将主要介绍在C/C++中时间和日期的使用方法 ...

  4. POJ 3928 Ping pong

    题目链接:http://poj.org/problem?id=3928 乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判 ...

  5. FUDCon - FedoraProject

    FUDCon - FedoraProject FUDCon: Fedora Users and Developers Conference FUD: An acronym for Fear, Unce ...

  6. 多线程——达到Runnable介面

    部分博客(多线程--继承Thread类)介绍了java多线程的第一种实现方法--继承Thread类.这篇博客介绍另外一种方法--实现Runnable接口,并实现run方法. 还用上篇博客的样例.如今用 ...

  7. Intel&lowbar;CS&lowbar;WebRTC 验证性测试

      机器: Centos 7.2 一.配置阿里云源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/Cen ...

  8. python&lowbar;库学习&lowbar;01

    一.python的库学习之 财经数据接口包 1.安装ThShare 直接pip install tushare 可能会出现缺少依赖库的情况,依次安装,大概有lxml,pandas,bs4,reques ...

  9. jedis &amp&semi; common pool

    http://mvnrepository.com/artifact/redis.clients/jedis http://mvnrepository.com/artifact/org.apache.c ...

  10. 读书笔记&lowbar;Effective&lowbar;C&plus;&plus;&lowbar;条款四十:明智而审慎地使用多重继承

    多重继承是一种比较复杂的继承关系,它意味着如果用户想要使用这个类,那么就要对它的父类也了如指掌,所以在项目中会带来可读性的问题,一般我们都会尽量选择用单继承去替代它. 使用多重继承过程容易碰到的问题就 ...