package com.shine.eiuop.utils;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {

public static void main(String[] args) {
// TODO Auto-generated method stub
// 查找的字符串
String line = "GET_DEP_INFO : \"InfoSendService.getDeptInfo\",";

String line2 = "QUERY_DETAIL:'InfoSendService2.getMsgInfoDetailDTOByInfoId',";
System.out.println(line.matches("(.*)Service.(.*)"));
//方法1:
//截取字符串中的单引号或者双引号的数据
System.out.println((line.split("\\.")[0].substring(line.split("\\.")[0].indexOf("\"")+1)).trim());
System.out.println((line2.split("\\.")[0].substring(line2.split("\\.")[0].indexOf("\'")+1)).trim());


//方法2:
//使用正匹配字符串中含有双引号
// 创建 Pattern 对象
Pattern p1=Pattern.compile("\"(.*?)\"");
// 创建 matcher 对象
Matcher m = p1.matcher(line);
while (m.find()) {
System.out.println("Found value: " +m.group().trim() );
System.out.println("Found value0: " + m.group(0) );
System.out.println("Found value1: " + m.group(1) );
}

}

}


//最终输出:
true
InfoSendService
InfoSendService2
Found value: "InfoSendService.getDeptInfo"
Found value0: "InfoSendService.getDeptInfo"
Found value1: InfoSendService.getDeptInfo

相关文章:

  • 2021-12-04
  • 2021-11-04
  • 2021-12-29
  • 2021-07-13
  • 2022-01-24
  • 2021-12-31
  • 2021-12-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2021-11-23
  • 2021-09-16
  • 2021-10-08
  • 2021-11-04
相关资源
相似解决方案