截取字符串中的单引号或者双引号的数据


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM