Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:26:52+00:00 2026-05-31T22:26:52+00:00

How to use string value as a part of regular expression in groovy? I’am

  • 0

How to use string value as a part of regular expression in groovy?
I’am writing ant build script using groovy, here is some snapshot:

<target name="groovy.showProperties">
    <groovy>
        class ShowProperties extends org.apache.tools.ant.Task {
            String nameMatch;   

            public void execute() {
                    project.properties.each
                        {prop ->
                           //I don't know how to obtain nameMatch value
                            if(prop.key ==~ /.*nameMatch.*/) 
                            {
                                println prop;
                            }
                        };

            }
        }
        project.addTaskDefinition('dump', ShowProperties)
    </groovy>

    <echo>example:</echo>
    <dump nameMatch="lang"/>
</target>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:26:53+00:00Added an answer on May 31, 2026 at 10:26 pm

    It should be:

    /.*${nameMatch}.*/
    

    Does that not work?

    Edit:

    Taking your example task, and wrapping it in a valid build.xml like so:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="ItWorks" basedir=".">
        <property environment="env"/>
    
        <path id="lib.path">
            <fileset dir="${env.GROOVY_HOME}">
                <include name="lib/*.jar"/>
            </fileset>
        </path>
    
        <taskdef name="groovy"
                 classname="org.codehaus.groovy.ant.Groovy"
                 classpathref="lib.path"/>
    
        <target name="groovy.showProperties">
            <groovy>
                class ShowProperties extends org.apache.tools.ant.Task {
                    String nameMatch;   
    
                    public void execute() {
                        project.properties.each { prop ->
                            if( prop.key ==~ /.*${nameMatch}.*/ ) {
                                println prop
                            }
                        }
                    }
                }
                project.addTaskDefinition('dump', ShowProperties)
            </groovy>
    
            <echo>example:</echo>
            <dump nameMatch="lang"/>
        </target>
    </project>
    

    I can then do:

    ant groovy.showProperties
    

    And I get the output:

    Buildfile: /Users/tim/Code/test/build.xml
    
    groovy.showProperties:
         [echo] example:
         [dump] user.language=en
    
    BUILD SUCCESSFUL
    Total time: 1 second
    

    No parse errors or anything… What version of Groovy are you using?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try use string as a regular expression pattern but I've following errors PHP
My string like this: { key: value’s, key2: value } I use json_decode() PHP
I know that for an integer, you can use: int value; I tried: string
Using regular expressions, I want to remove all instances of a certain value unless
I'm looking for a regular expression to use in Refex.Replace that allows me to
I want to use a particular string found in the Values folder into normal
Currently, I use value converters to generate user-friendly strings for the GUI. As an
If I use String.intern() to improve performance as I can use == to compare
I want to use string similarity functions to find corrupted data in my database.
To add a whitespace seperator in a string we use String.Join(). My question:What(and how)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.