How to use multiple path patterns inside Sling Filter? | Community
Skip to main content
jayv25585659
Level 8
September 10, 2025
Solved

How to use multiple path patterns inside Sling Filter?

  • September 10, 2025
  • 2 replies
  • 301 views

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.html#pattern--), 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" })

 

 

Best answer by SantoshSai

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

 

2 replies

TarunKumar
Community Advisor
Community Advisor
September 10, 2025

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

SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
September 12, 2025

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
jayv25585659
Level 8
September 18, 2025

thank you for mentioning "?:" I'm not familiar with it.