[英]How to extract the String in these 3 cases using Regex with Java
I´m dealing with one problem. 我正在处理一个问题。 I have three strings that I want to extract only the String.
我有三个只想提取字符串的字符串。
Observações da #{loginBean.centralCreditoRole ? 'central de crédito' : 'loja'}
#{resource['images:header_logo_client.png']}
#{propostaCartaoBean.pojo.inss.exclusaoDataprevAgendada ? 'Sim' : 'Não'}
In line 1 the output will be 3 strings, Observações da
, central de crédito
, loja
. 在第1行的输出将是3个字符串,
Observações da
, central de crédito
, loja
。 Line 2 will be blank and Line 3 Sim
and Não
. 第2行为空白,第3行为
Sim
和Não
。
I got line 2 like this teste.replaceAll("\\\\#.+?\\\\}", "");
我得到了像这样的
teste.replaceAll("\\\\#.+?\\\\}", "");
行teste.replaceAll("\\\\#.+?\\\\}", "");
Is it possible to deal this problem? 有可能解决这个问题吗?
Thanks 谢谢
Your input is not sufficient enough to understand your need. 您的输入不足以了解您的需求。 However, you can try this example:
但是,您可以尝试以下示例:
String input = "Observações da #{loginBean.centralCreditoRole ? 'central de crédito' : 'loja'}";
Pattern pattern = Pattern.compile("(.*?)#.*?\\?\\s*(?:'(.*?)(?<!\\\\)'\\s+:\\s+'(.*?)(?<!\\\\)')?");
Matcher m = pattern.matcher(input);
while (m.find()) {
System.out.println(m.group(1));
System.out.println(m.group(2));
System.out.println(m.group(3));
}
This one is showing how it can parse the three portions from your first input. 该示例说明了如何解析您的第一个输入中的三个部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.