zoukankan      html  css  js  c++  java
  • [转]正则表达式语法

    语法 意义 说明
    "." 除换行符外的任意字符  
    "^" 字符串开始 '^hello'匹配'helloworld'而不匹配'aaaahellobbb'
    "$" 字符串结尾 与上同理
    "*"  匹配前一个字符0次或则多次(贪婪匹配) <*>匹配<title>chinaunix</title>
    "+" 匹配前一个字符1次或则多次(贪婪匹配) 与上同理
    "?" 匹配前一个字符0次或则1次(贪婪匹配) 与上同理

    *?

    +?

    ??

    以上三个取第一个匹配结果(非贪婪匹配)

    单独来看是贪婪,结合就变非贪婪

    <*>匹配<title>
    {m,n} 对于前一个字符重复m到n次,{m}亦可 a{6}匹配6个a、a{2,4}匹配2到4个a
    {m,n}? 对于前一个字符重复m到n次,并取尽可能少 ‘aaaaaa'中a{2,4}只会匹配2个
    "\" 特殊字符转义或者特殊序列  
    [] 表示一个字符集 [0-9]、[a-z]、[A-Z]、[^0]
    "|" A|B,或运算
    (...) 匹配括号中任意表达式  
    (?#...) 注释,可忽略  
    (?=...) Matches if ... matches next, but doesn't consume the string. '(?=test)'  在hellotest中匹配hello
    (?!...) Matches if ... doesn't match next. '(?!=test)'  若hello后面不为test,匹配hello
    (?<=...)  Matches if preceded by ... (must be fixed length). '(?<=hello)test'  在hellotest中匹配test
    (?<!...) Matches if not preceded by ... (must be fixed length). '(?<!hello)test'  在hellotest中不匹配test
    [^abc] not a, b, or c  
    A 只在字符串开始进行匹配  
     只在字符串结尾进行匹配  
     匹配位于开始或结尾的空字符串  
    B 匹配不位于开始或结尾的空字符串  
    d 数字,相当于[0-9]  
    D 非数字,相当于[^0-9]  
    s

    匹配任意空白字符:[ v、、空格]

     
    S 匹配任意非空白字符:[^ v]  
    w 匹配任意数字和字母:[a-zA-Z0-9]  
    W 匹配任意非数字和字母:[^a-zA-Z0-9]  
    [a-g] character between a & g  
    [abc] any of a, b, or c  
    tab, linefeed, carriage return  
    u00A9 unicode escaped ©  
  • 相关阅读:
    Linux下nginx 的常用命令
    Mybatis generator 自动生成代码(2)
    Android Retrofit2 网路编程
    Android webView输出自定义网页
    Android Studio OkHttpClient使用
    Android Studio SVN使用
    Android Toolbar的使用 顶部标题栏+后退键
    Android DrawLayout + ListView 的使用(一)
    RabbitMQ配置与安装
    Struts2拦截器
  • 原文地址:https://www.cnblogs.com/idbeta/p/5439567.html
Copyright © 2011-2022 走看看