Hi Base,
could it be that Regexes in Field Transforms are not greedy?
I am using this field transformation to extract sld.tld from hostnames:
[hostname_query_sub1]
CLEAN_KEYS = 1
MV_ADD = 0
SOURCE_KEY = querystring1
REGEX = ([^\.]+\.[^\.]+\.[^\.]+)
FORMAT = t2d::$1
Which gives these results:
1.2.3.4.in-addr.arpa -> 1.2.3
subdomain.subdomain.sld.tld -> subdomain.subdomain.sld
Using REGEX = ([^\.]+\.[^\.]+\.[^\.]+)$
works as intended:
1.2.3.4.in-addr.arpa -> 4.in-addr.arpa
subdomain.subdomain.sld.tld -> subdomain.sld.tld
Shouldn't the expression match to the end of the string even without "$"?
It's working as you've instructed it to. The expression you've supplied will not match until the end of the string because you've explicitly specified that it should only match characters that are NOT a period ("."). The regex engine will return the earliest match it will find - this is not to be confused with whether the match itself is greedy or not, that's simply default regex engine operation. Greediness in matches is whether they will try to match as long as possible or not.
If you want the last three groups before the end of the string, you need to anchor the match at the end of the string, just like you've done in the last regex in your post.
It's working as you've instructed it to. The expression you've supplied will not match until the end of the string because you've explicitly specified that it should only match characters that are NOT a period ("."). The regex engine will return the earliest match it will find - this is not to be confused with whether the match itself is greedy or not, that's simply default regex engine operation. Greediness in matches is whether they will try to match as long as possible or not.
If you want the last three groups before the end of the string, you need to anchor the match at the end of the string, just like you've done in the last regex in your post.
It's fast, I would write it in the same way 🙂
Thank you for the explation. So my first char class does not walk past the first dot - thanks. If I may follow-up on normal regex behavior: Ist this regex method (negate with anchor) fast, or could this be further optimized?