I need to get all characters between a particular expression. For example below is my sample document This is a sample document.
$if ( $variable) FIRST This text can be repeated many times until do while is called. $elseif($variable2) Some sample text follows this. $endif
I need to get all the characters between $if($variable)
and $elseif($variable)
OR if $elseIf
is not there, then between $if($variable)
and $else
OR if $else
is not there then between $if($variable)
and $endif
.
I don't know how to give OR condition if particular expression is not there.
I tried giving \\#if\\s*\\((.*?)\\)(.*?)\\#elseif|#else|#endif
. But the while(matcher.find())
loop is getting called three times. Is it possible to handle this in regular expression. Only one condition must be satisfied. If that condition is satisfied the other conditions need not be called. Please help me.