Support Questions

Find answers, ask questions, and share your expertise

How do I use ReplaceText processor to mask a portion of all the IP addresses found in a multi-line input FlowFile's content

avatar
Master Mentor

Hello,

We have a requirement to anonymize IP address. So we would identify IP address and replace the last part with some arbitrary value.

We have tried using the following regex for that (with "Regex Replace" for replacement strategy, "Line-by-Line" as evaluation mode)

(1) \\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}

(2) ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$

(3) ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)

None of this works.

Can you help me with the right value of regex we can use and the replacement value as well.

Thank you in advance!

1 ACCEPTED SOLUTION

avatar

Try this with a ReplaceText processor:

12570-zgzja.png

Here is the complete Search Value property:

((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))

@anshuman Ghosh

View solution in original post

3 REPLIES 3

avatar
Master Mentor

@Anshuman Ghosh I posted your question here for you.

avatar

Try this with a ReplaceText processor:

12570-zgzja.png

Here is the complete Search Value property:

((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)).((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))

@anshuman Ghosh

avatar
Master Mentor

@Anshuman Ghosh

The Search Value Regex above has 4 capture groups from a valid IP address. Each capture group can then be referenced in the replacement Value as $1, $2, $3, and/or $4. In the example above the replacement for each found valid IP is still the first two numbers followed by ".x.x". You can of course change the replacement value to whatever meets your specific needs.

Thanks,

Matt