΢ Ͷ ^ ھ

江苏队cba赛程 :JavatPPatternMatcherĿ

cba㶫 www.axwwg.com  •rg2020-01-15 15:59:38   ߣ   ҪuՓ(0)

ƪӛڌWJavat_ʽrWĺĿ
ȁff Matcher ȡĽYgroup()ӣ

matches():ƥֻ

ƪӛڌWJavat_ʽrWĺĿ

ȁff Matcher ȡĽYgroup()ӣ

  • matches():ƥַֻȫƥɹŷTruetFalseǰƥɹƄ´ƥλeַ"a123",t_ʽ"\w\d\d\d"tmatches()ŷtrueQ֮ҪƥַҪt_ʽһһĸĸ֌ԷQ֮ȫƥeһλ@⻨ҺLrgWѵĶ]ἰҲS
  • find():ƥĮǰλ_ʼƥҵһƥӴƄ´ƥλ?find()ǘǰvݔַ??--ժԡJava˼?”Ëеfind()Ҫƥַ"a123b"t_ʽ"\d\d\d"ݔY飺123ԷQ֮鲿ƥֻҪͷtrue
  • lookingAt():ƥǏĵһַMƥ,ƥɹ˲^mƥƥʧ,Ҳ^mƥlookingAt()matches()find()֮glookingAt()IJƥָĵһλ_ʼƥһλ]ƥ䵽Ͳƥֱӷfalseһλƥ䵽tƥڶλԴӣҪƥַ"a123b"t_ʽ"\w\d\d"ݔY"a12"ܺһλһλƥƥ䵽˾ƥһλ"\w\d\d"@tô"ĸ֔"ݔYa12

Ϝyԇa

package com.wjj.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author  : ե˸
* @version rg2016818 8:47:58
* ft_ʽľ
*/
public class Regex {
  //findyԇ
  public static void find(String html) {
    String regex = "\\d\\d\\d";
    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(html);
    System.out.print("find():");
    if (matcher.find()) {
      System.out.println(matcher.group());
    }
  }
  //matchesyԇ
  public static void matches(String html) {
    String regex = "^\\w\\d\\d\\d";
    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(html);
    System.out.print("matches():");
    if (matcher.matches()) {
      System.out.println(matcher.group());
    }
  }
  //lookingAtyԇ
  public static void lookingAt(String html) {
    String regex = "\\w\\d\\d";
    Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(html);
    System.out.print("lookingAt():");
    if (matcher.lookingAt()) {
      System.out.println(matcher.group());
    }
  }
  public static void main(String[] args) {
    //findyԇ
    find("a123b");
    //matchesyԇ
    matches("a123");
    //lookingAtyԇ
    lookingAt("a123b");
  }
}

ݔY

    find():123
    matches():a123
    lookingAt():a12

СYt_ʽyƽʹõĕrֻҪҎt팑ͺڌWmatchesfindlookingAtұ^LĕrgһֱȫƥͲƥʲô˼߀stackoverflowҵҪĴ

ǂˌWв֮̎ϣoָc

a䣺t_ʽPattern{ö׳}ȴPatternÿһξ;gһt_ʽ˽hҪt_ʽMAg

t_ʽW̳̣ //deerchao.net/tutorials/regex/regex.htm ߌͦԔͨ׶

Y

СoҽBJavatPPatternMatcherĿ,ϣκɆՈoСr؏ʹҵڴҲdzxҌ_֮ҾWվ֧
XñČЎgӭDdՈע̎xx

ܸdȤ:

  • Java NumberFormatʽfloat͵bug
  • Java NumberFormat Ԕ⼰
  • javaweb HDateFormatNumberFormatMessageFormatResourceBundleʹ
  • javaFڕrgDQʾ
  • JavaFķ퓹c÷ʾ
  • java@ȡ±ָע^̽
  • Javaԭςļ ʹMultipartFile
  • Java Numberԭ팍

P