首页 > 编程语言 >Java: Regular Expressions

Java: Regular Expressions

时间:2022-11-27 22:44:58浏览次数:40  
标签:CASE search Java Pattern will Regular pattern Expressions Match

  • Pattern Class - Defines a pattern (to be used in a search)
  • Matcher Class - Used to search for the pattern
  • PatternSyntaxException Class - Indicates syntax error in a regular expression pattern
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
  public static void main(String[] args) {
    Pattern pattern = Pattern.compile("w3schools", Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher("Visit W3Schools!");
    boolean matchFound = matcher.find();
    if(matchFound) {
      System.out.println("Match found");
    } else {
      System.out.println("Match not found");
    }
  }
}
// Outputs Match found
  • Pattern.CASE_INSENSITIVE - The case of letters will be ignored when performing a search.
  • Pattern.LITERAL - Special characters in the pattern will not have any special meaning and will be treated as ordinary characters when performing a search.
  • Pattern.UNICODE_CASE - Use it together with the CASE_INSENSITIVE flag to also ignore the case of letters outside of the English alphabet

 

标签:CASE,search,Java,Pattern,will,Regular,pattern,Expressions,Match
From: https://www.cnblogs.com/ShengLiu/p/16930913.html

相关文章

  • Java中使用正则表达式
    1、使用 java.util.regex.Pattern类的 compole(表达式)方法把正则表达式变成一个对象。//表达式对象:1个数字和1个字母连续Patternpattern=P......
  • Java入门代码练习
    一、第一个Java程序1、helloworldpublicclassHello{publicstaticvoidmain(String[]args){System.out.println("Helloworld!");}}2、变量i......
  • Java Excel导出动态自定义单元格样式
    根据表格内容定义单元格样式效果图:文章描述两种,一种创建生成时定义样式,另一种在excel在写入文件前修改样式关键代码一/***数据动态设置样式*......
  • 用Java打印一个9层空心菱形
    publicclassRhombus{publicstaticvoidmain(Stringargs[]){      for(inti=1;i<=5;i++){  //i表示层数      //空格个数    ......
  • Java: Exceptions - Try...Catch
    tryandcatch  Usetryandcatch:publicclassMain{publicstaticvoidmain(String[]args){try{int[]myNumbers={1,2,3};Syst......
  • Java: Wrapper Classes
    Wrapperclassesprovideawaytouseprimitivedatatypes(int, boolean,etc..)asobjects.PrimitiveDataTypeWrapperClassbyteByteshortShortint......
  • Java: Iterator
    An Iterator isanobjectthatcanbeusedtoloopthroughcollections,like ArrayList and HashSet.//ImporttheArrayListclassandtheIteratorclassi......
  • 线程总述(Java版)
    一、线程创建1、继承Thread类首先,自定义线程类继承THread类;其次,重写run方法,编写线程执行体;最后,创建线程对象并调用start()方法启动线程。但值得注意的是,线程并不一定......
  • 自用_Minecraft Java Server配置、指令等等提示
    尚未写完gamemode=(模式)//adventure冒险模式、creative创造模式、survival生存模式、spectator旁观者模式。online-mode=//用于验证玩家是否“在线”,也就是是否是正版......
  • 又一巨头从 Java 迁移到 Kotlin,简直很无语。。
    出品|OSC开源社区(ID:oschina2013)Meta发布了一篇博客表示,正在将其Android应用的Java代码迁移到Kotlin,并分享了这一过程中的一些经验。该公司认为,Kotlin是一种流行的......