“正则表达式”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第14行: 第14行:
  
 
[https://c.runoob.com/front-end/7625/#!flags=&re=%5E(a%7Cb)*%3F%24 https://c.runoob.com/front-end/7625]
 
[https://c.runoob.com/front-end/7625/#!flags=&re=%5E(a%7Cb)*%3F%24 https://c.runoob.com/front-end/7625]
 +
 +
简单使用的示例:<syntaxhighlight lang="java">
 +
import java.util.regex.Pattern;
 +
 +
public class Hello {
 +
    public static void main(String[] args) {
 +
 +
        String content = "I am hsp from hspedu.com.";
 +
        String pattern = ".*hspedu.*";
 +
        boolean isMatch = Pattern.matches(pattern, content);
 +
        System.out.println("是否整体匹配成功:" + isMatch);
 +
 +
    }
 +
}
 +
</syntaxhighlight>
  
  

2022年11月19日 (六) 08:41的版本

https://www.bilibili.com/video/BV1Eq4y1E79W


元字符大全:

https://www.runoob.com/regexp/regexp-metachar.html


可视化工具:

https://regexper.com/

https://c.runoob.com/front-end/7625

简单使用的示例:

import java.util.regex.Pattern;

public class Hello {
    public static void main(String[] args) {

        String content = "I am hsp from hspedu.com.";
        String pattern = ".*hspedu.*";
        boolean isMatch = Pattern.matches(pattern, content);
        System.out.println("是否整体匹配成功:" + isMatch);

    }
}


正则表达式 初体验

正则表达式 应用场景

正则表达式 底层实现

语法

分组

非捕获分组

非贪婪匹配

应用实例

验证复杂URL

[] 的应用

Pattern 类

Matcher 类

PatternSyntaxException 是一个非强制异常类,它表示一个正则表达式模式中的语法错误。

[] 和 () 的区别:

[] 括起来的是字符集合;

() 主要表示匹配后分组捕获。