使用java正则表达式,如何使用“获取组值”;()";一串
我有条件:使用java正则表达式,如何使用“获取组值”;()";一串,java,regex,Java,Regex,我有条件: @Table(name = "T_MEM_MEMBER_ADDRESS1") @Table( name = "T_MEM_MEMBER_ADDRESS2") @Table ( name = "T_MEM_MEMBER_ADDRESS3" ) 我想编写一个regex,它可以获取name值,例如: T_MEM_MEMBER_ADDRESS1 T_MEM_MEMBER_ADDRESS2 T_MEM_MEMBER_ADDRESS3 我写 String regexPatt
@Table(name = "T_MEM_MEMBER_ADDRESS1")
@Table( name = "T_MEM_MEMBER_ADDRESS2")
@Table ( name = "T_MEM_MEMBER_ADDRESS3" )
我想编写一个regex,它可以获取name值,例如:
T_MEM_MEMBER_ADDRESS1
T_MEM_MEMBER_ADDRESS2
T_MEM_MEMBER_ADDRESS3
我写
String regexPattern="...";
Pattern pattern = Pattern.compile(regexPattern);
Matcher matcher = pattern.matcher(input);
boolean matches = matcher.matches();
if (matches){
log.debug(matcher.group(1));
}
但是我无法编写regexpatern..您可以使用此正则表达式:
(?<=")(.+)(?=")
(?您可以使用这段代码:
String input = "@Table(name = \"T_MEM_MEMBER_ADDRESS1\")";
String regexPattern=".*\"(.*)\".*";
Pattern pattern = Pattern.compile(regexPattern);
Matcher matcher = pattern.matcher(input);
boolean matches = matcher.matches();
if (matches){
System.out.println(matcher.group(1));
}
希望有帮助。你仍然需要避开引号:”(?如果我不想匹配/@Table(name=“t\u MEM\u MEMBER\u ADDRESS”)
和/@Table(name=“t\u MEM\u MEMBER\u ADDRESS”)
,如何写?@AmitJoki我的意思是,如果我的字符串也有/@Table(name=“t\u MEM\u MEMBER\u ADDRESS”)
对于//注释,我不希望我的regexpatern与此字符串匹配
String input = "@Table(name = \"T_MEM_MEMBER_ADDRESS1\")";
String regexPattern=".*\"(.*)\".*";
Pattern pattern = Pattern.compile(regexPattern);
Matcher matcher = pattern.matcher(input);
boolean matches = matcher.matches();
if (matches){
System.out.println(matcher.group(1));
}