Help with java regular expressions
Hi all ,
i am going to match a patternstring against an input string and print the result here is my code:
import java.util.regex.*;
import java.util.*;
publicclass Main{
privatestaticfinal String CASE_INSENSITIVE =null;
publicstaticvoid main(String[] args)
{
CharSequence inputStr ="i have 5 years FMCG saLEs exp on java/j2ee and i worked on java and j2ee and 2 projects on telecom java j2ee domain with your with saLEs maNAger experience of java j2ee and c# having very good on c++ exposure in JAVA"
String patternStr ="\"java j2ee\" and \"c#\"";
StringTokenizer st =new StringTokenizer(patternStr,"\",OR");
Matcher matcher=null;
while(st.hasMoreTokens()){
String s=st.nextToken();
Pattern pattern = Pattern.compile(s,Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(inputStr);
while (matcher.find()){
String result = matcher.group();
if(!result.equalsIgnoreCase(" "))
{
System.out.println("result:"+result);
}
}
}
}
}
when i compile this code i am getting the expected result...ie
result:java j2ee
result:java j2ee
result: and
result: and
result: and
result: and
result: and
result: and
result:c#
but when i replace String patternStr = "\"java j2ee\" and \"c#\"";with
String patternStr = "\"java j2ee\" and \"c++\"";i am just getting c in the result instead of c++ ie i am getting result :
result:java j2ee
result:java j2ee
result: and
result: and
result: and
result: and
result: and
result: and
result:C
result:c
result:c
result:c
result:c
result:c
result:c
In the last lines i should get result:c++instead of result: c
Any ideas please
Thanks

