-3

I have come across the following regular expression in a program and struggling to understand what is trying to do. Can anyone help me please? I have only started to learn this

l = Z + lo <= lf ? lo : lf - z;
dee-see
  • 23,668
  • 5
  • 58
  • 91

1 Answers1

1

That's most likely the use of a ternary operator, despite its cryptic appearance which is usually attributed to RegExps:

l = ((z + lo) <= lf) ? lo : (lf - z);

This is another way of writing the following:

if(z + lo <= lf)
    l = lo;
else
    l = lf - z;

This doc covers the ternary operator:

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html

Related SO post:

How does the ternary operator work?

Edit: The code you posted can be used as a Regex: http://www.rubular.com/r/Svr9S7EaCP

Community
  • 1
  • 1
pcnThird
  • 2,362
  • 2
  • 19
  • 33