Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

How to use multiple path patterns inside Sling Filter?

Avatar

Level 9

might be best explained with an example. Thanks for the assistance.

 

EDIT: Accordingt to this page https://sling.apache.org/apidocs/sling11/org/apache/sling/servlets/annotations/SlingServletFilter.ht...), pattern accepts regex value.

 

This one works.

(service = Filter.class, property = {
        "sling.filter.scope=REQUEST",
        "sling.filter.pattern=^/content/myapp/sg/en/login.*",
        "service.ranking:Integer=100"
})

This one does not work.

(service = Filter.class, property = {
        "sling.filter.scope=REQUEST",
        "sling.filter.pattern=^/content/myapp/sg/en/(login|members).*",
        "service.ranking:Integer=100"
})

 

 

2 Replies

Avatar

Community Advisor

Hi @jayv25585659 ,

The syntax for second pattern doesn't look good. Can you try to use something like below:

(service = Filter.class, property = {
        "sling.filter.scope=REQUEST",
        "sling.filter.pattern=((^/content/myapp/sg/en/login.*) |(/content/myapp/sg/en/members.*))",
        "service.ranking:Integer=100"
})

 

 

Hope ite helps!

-Tarun

Avatar

Community Advisor

Hi @jayv25585659,

Try this with one regex or by registering multiple patterns as separate filter instances. The sling.filter.pattern property itself is a single regex string, not a list.

@Component(service = Filter.class, property = {
  "sling.filter.scope=REQUEST",
  "sling.filter.pattern=^/content/myapp/sg/en/(?:login|members)(?:$|/|\\.|\\?).*",
  "service.ranking:Integer=100"
})

 


Santosh Sai

AEM BlogsLinkedIn