Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Why is there an error on the colon in ${attribute:find...?

avatar
Explorer

I want to use RouteOnAttribute to filter on a regex. To do so, I added two attributes in the Properties:

 

PropertyValue
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?

 

1 ACCEPTED SOLUTION

avatar
Explorer

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.

View solution in original post

3 REPLIES 3

avatar
Super Collaborator

You probably need to escape the $ which is a special character in NiFi...try adding \ or \\

 

joseomjr_0-1687655182513.png

 

avatar

@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)} )}

avatar
Explorer

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.