I couldn’t define a regular expression between "=" and "==". To explain more clear, look at the codes.
if(Pattern.matches("(.*)=(.*)", text))
{
// code block 1
}
if(Pattern.matches("(.*)==(.*)", text))
{
// code block 2
}
Sample text1 : asdasdasd=asdasdasd
Sample text2 : asdasdasd==asdasdasd
When the text be like above samples, in any case only code block 1 is working.
Also I know "( .* )=( .* )" this expression is wrong. I tried "(.*)=(^=)" etc. but I couldn’t figure out. I want to find solution which if text has a "=", code block 1 works, if text has "==", code block 2 works.
>Solution :
To exclude a character, that isn’t (^=), but between square brackets [^=], giving either :
(.*[^=])=([^=].*)(.*)(?<!=)=(?!=)(.*)with negatives lookahead+lookbehind
Or could work with String.contains, in the right order
if (text.contains("==")) {
System.out.println("Case 2");
} else if (text.contains("=")) {
System.out.println("Case 1");
}