博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
正则表达式对JX8NET很有用 给定一段文章 查找hi这个单词
阅读量:3517 次
发布时间:2019-05-20

本文共 1189 字,大约阅读时间需要 3 分钟。

地址:

正则表达式对很有用 给定一段文章,查找hi这个单词。

\bhi\b
3.我要找出这样的一个字符串,包含is,然后,在is后面跟着一个perfect。
\bis\b.*\bperfect\b

package com.pattern.test;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class PatternTest {

       public static void main(String[] args) {

              String pattern = "\\bis\\b.*\\bperfect\\b";

              String testStr = "RegexBuddy is your perfect companion for working with regular expressions";

               // pattern = args [0];

               // testStr = args [1];

              Matcher matcher = Pattern. compile(pattern).matcher(testStr);

               if (matcher.find()) {

                     System. out.println("[" +testStr+"]" + " matches pattern " +"["+ pattern+"]" );

                     

                     System. out.println("After replace, the new testStr is:[" + matcher.replaceFirst("TARGET" )+"]" );

                     System. out.println("the origl testStr is:[" + testStr+"]");

              } else {

                     System. out.println("[" +testStr+"]" + " does not match pattern " + "["+ pattern+ "]");

              }

       }

}

-----

输出:

[RegexBuddy is your perfect companion for working with regular expressions] matches pattern [\bis\b.*\bperfect\b]

After replace, the new testStr is:[RegexBuddy TARGET companion for working with regular expressions]

the origl testStr is:[RegexBuddy is your perfect companion for working with regular expressions]

转载地址:http://dhxqj.baihongyu.com/

你可能感兴趣的文章
牛客的AI模拟面试(1)
查看>>
深入浅出MyBatis:MyBatis解析和运行原理
查看>>
Mybatis与Ibatis
查看>>
字节码文件(Class文件)
查看>>
java中的IO流(一)----概述
查看>>
StringBuilder
查看>>
集合,Collection
查看>>
泛型详解
查看>>
泛型实现斗地主
查看>>
List集合
查看>>
ArrayList集合,LinkedList集合,Vector集合
查看>>
HashSet集合
查看>>
并发与并行,线程与进程
查看>>
方法引用,通过对象名引用成员变量
查看>>
常用工具类 Math:数学计算 Random:生成伪随机数 SecureRandom:生成安全的随机数 2020-2-13
查看>>
Java的异常Exception 2020-2-13
查看>>
Java标准库定义的常用异常,自定义异常 2020-2-15
查看>>
Java问题百度/Google记录 2020-2-16
查看>>
【PADS9.5】9,对比ECO核心板,Router移动元件后布线消失,Router找不到自动布线策略文件丢失或损坏
查看>>
【STM32+w5500汇总】23,HTTP_Client 连接到ONENET上传了一段数据之后会断开,数据上传格式的设置
查看>>