Finding Elvis ?:

I was instructed to find Elvis (using the eclipse search). Is there any regex that I can use to find it?

The Elvis Operator ( ?:) is an abbreviation of the Java ternary operator.

I tried \?[\s\S]*[:], but it does not match multi-line.
Is there any refactoring where I could change Elvis into an if-else block?

+5
source share
2 answers

Edit Unfortunately, I wrote a regular expression for the ternary operator, if your problem is multi-line, you can use this:

\?(\p{Z}|\r\n|\n)*:
+4
source

, . \R ( ), Eclipse 3.4 , (\ r,\n,\r\n). . \?.*\R*.*: , . \R , , , , , . - ([-\r\n\w\s\[\](){}=!/%*+&^|."']*)\?([-\r\n\w\s\[\](){}=!/%*+&^|."']*):([-\r\n\w\s\[\](){}=!/%*+&^|."']*). , .

, , Java (, , ). ?: , if . :

boolean even = true;
int foo = even ? 2 : 3;
int bar = if (even) 2 else 3;

; . (, , , if (int foo = even) 2 else 3;, .)

, ?: ( - , , , ), "if '.

+2

All Articles