Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: further alternatives

...

Code Block
event:attrs{"url"}.extract(re#http://([^/:]+)#)

Other alternatives

Besides the alternatives shown above (short form that is deprecated, and the official form), there are other ways to obtain an event attribute’s value inside a rule. The first two above are expressions which can appear anywhere a KRL expression can appear (the where clause of a select when, the prelude of a rule, the condition of a rule, and a postlude of a rule, the expression in a foreach, etc.).

In addition, an expression like the following could be used anywhere a KRL expression can appear:

Code Block
event:attrs.get("url").extract(re#http://([^/:]+)#)

That works because event:attrs evaluates to a KRL map, so that any of Map Operators and expressions can be used with it. As an additional example, if we just wanted to see if the attributes included an attribute named “url” we could use:

Code Block
event:attrs >< "url"

Finally, as one of the matches in a select when we could use (see Event Expressions in the Grammar page):

Code Block
url re#http://([^/:]+)# setting(domain)

This does more than simply extract the domain name from an event attribute named “url” but causes the rule to be selected only when there actually is an attributed named “url” associated with the event. Furthermore, it binds the domain portion of said URL to the name domain which is now in scope for the entire rule.

Sending an event attribute

...