-4

I am Using Regular Expression to break the string, I am trying to break the string but In reqular Expressions I am missing some format. Can any one please let me know where i went wrong.

String betweenstring="['Sheet 1$'].[DEPTNO] AS [DEPTNO]";
System.out.println("betweenstring: "+betweenstring);
Pattern pattern = Pattern.compile("\\w+[.]\\w+");
Matcher matchers=pattern.matcher(betweenstring);    
while(matchers.find())
{       
    String filtereddata=matchers.group(0);          
    System.out.println("filtereddata: "+filtereddata);
}

I need to break like this:

['Sheet 1$']
[DEPTNO] AS [DEPTNO]
Navyah
  • 1,660
  • 10
  • 33
  • 58

1 Answers1

2

Given your very specific input, this regex works.

([\w\[\]' $]+)\.([\w\[\]' $]+)

Capture group one is before the period, capture group 2, after. To escape this for a Java string:

Pattern pattern = Pattern.compile("([\\w\\[\\]' $]+(\\.*[\\w\\[\\]' $]+)");

However, it would be much easier to split the string on the literal dot, if this is what you are trying to achieve:

String[] pieces = between.split("\\.");
System.out.println(pieces[0]);    
System.out.println(pieces[1]);

Output:

['Sheet 1$']
[DEPTNO] AS [DEPTNO]
aliteralmind
  • 19,847
  • 17
  • 77
  • 108