• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • Introduction
      • How to install bnd
      • Guided Tour Workspace & Projects
      • bnd / bndlib Features and JAR Wrapping Techniques
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Concepts
      • Background
      • Best practices
    • Build and Development
      • Build
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • bnd CLI Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • filter ';' LIST ';' REGEX

    Prev Next
    Macro
    Filter a list to include only entries matching a regular expression

    Summary

    The filter macro filters a list to include only those entries that match a specified regular expression pattern. Entries that don’t match are removed from the result.

    Syntax

    ${filter;<list>;<regex>}
    

    Parameters

    • list - A comma or semicolon-separated list of values
    • regex - A Java regular expression pattern to match against

    Behavior

    • Splits the input list into individual entries
    • Compiles the regex pattern
    • Tests each entry against the pattern using full match semantics
    • Keeps only entries that match the pattern
    • Returns the filtered list as a comma-separated string
    • Empty result if no entries match

    Examples

    Filter for JAR files:

    ${filter;foo.jar,bar.txt,baz.jar;.*\.jar}
    # Returns: "foo.jar,baz.jar"
    

    Filter package names:

    ${filter;com.example.api,com.example.impl,org.other;com\.example\..*}
    # Returns: "com.example.api,com.example.impl"
    

    Filter versions:

    ${filter;1.0.0,2.0.0-SNAPSHOT,2.1.0;.*SNAPSHOT.*}
    # Returns: "2.0.0-SNAPSHOT"
    

    Filter by prefix:

    ${filter;test-bundle,main-bundle,test-util;test-.*}
    # Returns: "test-bundle,test-util"
    

    Use Cases

    • Selecting specific files from a list
    • Filtering packages or classes by naming patterns
    • Extracting specific versions from a list
    • Building selective classpaths
    • Conditional inclusion based on naming conventions
    • Cleaning up lists to match specific criteria

    Notes

    • Uses Java regular expression syntax
    • The pattern must match the entire entry (full match, not substring)
    • Case-sensitive by default (use (?i) for case-insensitive matching)
    • See also: ${filterout} (or ${reject}) for inverse filtering
    • See also: ${select} which is an alias for ${filter}

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home