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

    Prev Next
    Macro
    Replace parts of a string using regex patterns

    Summary

    The replacestring macro applies regex-based replacement to a single string, supporting back-references for captured groups.

    Syntax

    ${replacestring;<string>;<regex>[;<replacement>]}
    

    Parameters

    • string - The string to process
    • regex - Regular expression pattern to match
    • replacement (optional) - Replacement string with $1-$9 back-references (default: empty)

    Behavior

    • Applies string.replaceAll(regex, replacement)
    • Supports regex back-references ($1, $2, etc.)
    • Default replacement is empty (removes matches)
    • All occurrences are replaced

    Examples

    Simple replacement:

    description: This is, possibly, the best implementation ever!
    ${replacestring;${description};possibly;definitely}
    # Returns: "This is, definitely, the best implementation ever!"
    

    Remove pattern:

    ${replacestring;version-1.2.3;version-;}
    # Returns: "1.2.3"
    

    Using back-references:

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

    Multiple replacements:

    ${replacestring;hello world;[aeiou];*}
    # Returns: "h*ll* w*rld"
    

    Path normalization:

    ${replacestring;${path};\\;/}
    # Replace backslashes with forward slashes
    

    Use Cases

    • String transformations
    • Pattern-based modifications
    • Text cleanup
    • Path normalization
    • Version string manipulation
    • String formatting

    Notes

    • Regex uses Java syntax
    • All occurrences replaced
    • Empty replacement removes text
    • For lists, use ${replace} or ${replacelist}
    • See also: ${replace} for list processing
    • See also: ${subst} for simple string substitution

    See test cases in MacroTestsForDocsExamples.java

Prev Next
Search
    • Home