I recommend you implement an Activity which has Property-Set step with examples of each of your 4 different patterns in it, then once use "View Java" from the Actions menu to inspect what Java code Pega generates to resolve each of those four expressions.
From that you will likely be able to produce a block of Java code that does what you need.
Look to then implement that in a Function rule so that you are not putting transient state onto the Parameter Page. Use local variables in your Function to hold interim values not required outside of the function.
Finally, have a look at how OTB Functions like PropertyExists and PropertyHasValue handle the different permutations of page and property references, there might be something to learn from there.