Issue
I have come up with a regex pattern to match a part of a Json value. But only PRCE engine is supporting this. I want to know the Java equalent of this regex.
Simplified version
cif:\K.*(?=(.+?){4})
Matches part of the value, leaving the last 4 characters.
cif:test1234
Matched value will be test
https://regex101.com/r/xV4ZNa/1
Note: I can only define the regex and the replace text. I don't have access to the Java code since it's handle by a propriotery log masking framework.
Solution
You can write simplify the pattern to:
(?<=cif:).*(?=....)
Explanation
(?<=cif:)
Positive lookbehind, assertcif:
to the left.*
Match 0+ times any character without newlines(?=....)
Positive lookahead, assert 4 characters (which can include spaces)
See a regex demo.
If you don't want to match empty strings, then you can use .+
instead
(?<=cif:).+(?=....)
Answered By - The fourth bird
Answer Checked By - Senaida (JavaFixing Volunteer)