• 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
  • replace ';' LIST ';' REGEX (';' STRING (';' STRING)? )?

    Prev Next
    Macro
    Replace parts of list elements using regex patterns

    Summary

    The replace macro applies regex-based replacement to each element in a comma-separated list. Uses simple comma splitting (doesn’t handle quoted sections).

    Syntax

    ${replace;<list>;<regex>[;<replacement>[;<delimiter>]]}
    

    Parameters

    • list - Comma-separated list of elements
    • regex - Regular expression pattern to match
    • replacement (optional) - Replacement string with $1-$9 back-references (default: empty)
    • delimiter (optional) - Output delimiter (default: “,”)

    Behavior

    • Splits list on commas (simple: \s*,\s*)
    • Applies element.replaceAll(regex, replacement) to each
    • Supports regex back-references ($1, $2, etc.)
    • Cannot handle commas within quoted sections
    • Returns delimited result

    Examples

    Add file extension:

    impls: foo,bar
    ${replace;${impls};$;.jar}
    # Returns: "foo.jar,bar.jar"
    

    Replace pattern:

    ${replace;v1.0,v2.0,v3.0;^v;version-}
    # Returns: "version-1.0,version-2.0,version-3.0"
    

    Using back-references:

    ${replace;com.example.api,com.example.impl;com\.example\.(.+);$1}
    # Returns: "api,impl"
    

    Custom delimiter:

    ${replace;a,b,c;$;-suffix;;}
    # Returns: "a-suffix;b-suffix;c-suffix"
    

    Use Cases

    • Adding prefixes/suffixes to list elements
    • Pattern-based transformations
    • File extension handling
    • List element modification
    • Bulk string operations

    Notes

    • Simple comma splitting only
    • For quoted sections, use ${replacelist}
    • Regex uses Java syntax
    • Empty replacement removes matched text
    • See also: ${replacelist} for quoted section support
    • See also: ${replacestring} for single string replacement

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home