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

[2845 byte] By [reddy2005a] at [2007-11-26 16:27:34]
# 1

> In the last lines i should get result:c++instead of result: c

The regular expression parser considers the plus sign '+' a special

character; it means: one or more times the previous regular expression.

So 'c++' means one or more 'c's on or more times. Obviously you don't

want that, you want a literal '+' plus sign. You can do that by prepending

the '+' with a backslash '\'. Unfortunately, the javac compiler considers

a backslash a special character and therefore you have to 'escape'

the backslash also, by adding another backslash. The result looks

like this:"c\\+\\+"

kind regards,

Jos

JosAHa at 2007-7-8 22:51:47 > top of Java-index,Java Essentials,Java Programming...
# 2
hi josah,Thank you very much for the response...that was very helpful for meRegards
reddy2005a at 2007-7-8 22:51:47 > top of Java-index,Java Essentials,Java Programming...