I am trying to search an element in a string using Pattern and matcher in Java.
i have a node variant-items and need to get all the characters coming between these nodes. i tried the below regex but it is skipping this line altogether. however if i search using the same regex in Notepad++ i am getting the desired resulted selected. please advice.
<variant-items>((.|\n)*)</variant-items>
Below is my implemenation
String patternSourceComponent = "<variant-items>((.|\n)*)</variant-items>";
String result=this.isMatched(patternSourceComponent, xml);
public String isMatched(String patternSourceComponent,String xml)
{
String varientItem="";
try{ Pattern patternComponent = Pattern.compile(patternSourceComponent);
Matcher matcherComponent = patternComponent.matcher(xml);
System.out.println("matcherComponent Find : "+matcherComponent.find());
while (matcherComponent.find()) {
varientItem=matcherComponent.group(0).trim();
System.out.println("varientItem : "+varientItem);
} }
catch (Exception e)
{
System.out.println("Exception : "+e);
}
return varientItem;
}