Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 06-23-2023 11:19 AM
I want to use RouteOnAttribute to filter on a regex. To do so, I added two attributes in the Properties:
| Property | Value |
| private | ${ip:find('^(10|127|169\.254|172\.1[6-9]|172\.2[0-9]|172\.3[0-1]|192\.168)\.')} |
| public | ${ip:find('^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?<!172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31))(?<!127)(?<!^10)(?<!^0)\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(?<!192\.168)(?<!172\.(16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31))\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')} |
This processor shows two errors, both the same: `Unexpected token ':' at line 1 column 4`
Why is this an error?
Created 06-26-2023 03:37 AM
The issue ended up being that ip is a reserved word (a default function) so changing the name of the attribute from ip to extractedIp solved it.
Created on 06-24-2023 04:37 PM - edited 06-24-2023 06:06 PM
You probably need to escape the $ which is a special character in NiFi...try adding \ or \\
Created 06-25-2023 11:53 PM
@Wpq,
I do not think that NiFi supports the full syntax of Java regular expressions directly, like you are trying to do, especially on attributes and using NiFi's Expression Language.
What I would recommend you to try is to use NiFi's EL to replace that entire regex, something like:
${ip:startsWith('10.') or ip:startsWith('127.') or ip:startsWith('169.254.') or (ip:startsWith('172.') and ip:substring(4, 6):matches('1[6-9]|2[0-9]|3[0-1]')) or ip:startsWith('192.168.')}
The above code is not 100% correct, I am more than certain, but you can extrapolate from that example and rewrite your query somehow like that. The NiFi EL functions you should use are:
OR:
${ fileSize:lt(64):or( ${fileSize:gt(128)} )}
StartsWith:
${ filename:startsWith('fizz') }
Matches:
${ filename:matches('fizz.*txt') }
And:
${ fileSize:gt(64):and( ${fileSize:lt(128)} )}
Created 06-26-2023 03:37 AM
The issue ended up being that ip is a reserved word (a default function) so changing the name of the attribute from ip to extractedIp solved it.