-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]
2
  • Define what "break the string" means Commented Apr 2, 2014 at 12:34
  • I have Updated Please once check Commented Apr 2, 2014 at 12:41

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.