ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Amerige <>
Subject Re: Negative Lookahead and Regexp
Date Thu, 10 Nov 2011 14:50:05 GMT
Hi Vimil,

Thanks for your reply.

Unfortunately, negate doesn't work as can be demonstrated with:

<target name="negate">
<property name="a.b.c.d" value="1"/>
<property name="a.b.c.e" value="2"/>
<property name="a.c.x.y" value="3"/>
<property name="p.q.r"   value="4"/>

<propertyset id="plus"><propertyref prefix="a."/></propertyset>
<propertyset id="minus" negate="true"><propertyref prefix="a.b."/></propertyset>
<propertyset id="union">
<propertyset refid="minus"/>
<propertyset refid="plus"/>
<propertyset refid="union"/>

If what I'm looking to find is "^a\.(?!b\.).*" ("a." followed by anything except for "b."),
then this doesn't work.  Of course, my 
real need isn't just this simple case, so a hack for this particular example won't be of much
help.  For example, cases such as the 
regexp "^a\..*(?!\.x|\.y|\.z)$" ("a." followed by anything, but not ending in ".x", ".y",
or ".z") are more complex.

What I have considered is that I can use <propertyselector> to grab all of the positive
matches and then remove all of the 
exclusions.  Then I'd have a list of the desired properties, but it is still not optimal because
that result isn't a propertyset 
that I can use where propertsets are used.

I've also wondered if a groovy script might be the best way to go.  Any pointers for either
of these workarounds?

Steve Amerige
SAS Institute, Deployment Software Development

On 11/10/2011 8:44 AM, Vimil Saju wrote:
> The propertyset type has a negate attribute. maybe that will help you.
> ------------------------------------------------------------------------------------------------------------------------------------
> *From:* Steve Amerige <>
> *To:* Ant Users List <>
> *Sent:* Thursday, November 10, 2011 4:50 AM
> *Subject:* Re: Negative Lookahead and Regexp
> Hi all,
> So, I'm guessing that Ant 1.7+ (with optional Ant-Contrib) doesn't support negative lookahead
regex searches.
> So, I'm refocusing on the main objective here: I want a propertyset that excludes properties
matching certain patterns.  Any idea as
> to how to accomplish this?
> Thanks!
> Steve Amerige
> SAS Institute, Deployment Software Development
> On 11/9/2011 3:40 PM, Steve Amerige wrote:
> > Hi all,
> >
> > Is negative lookahead supported at all in Ant 1.7 and higher (Ant-Contrib, too)?
 Maybe my syntax is off:
> >
> > <propertyregex property="result" input="a.b.c.bad" select="\1" regexp="(.*(?!bad))"
defaultValue="" override="true"/>
> > <propertyregex property="result" input="a.b.c.ok" select="\1" regexp="(.*(?!bad))"
defaultValue="" override="true"/>
> >
> > The first result should be the empty string and the second result should be "a.b.c.ok".
 I'm also looking to use this idea in
> > <propertyset> to exclude certain properties.
> >
> > See the regular expression page on this:
> >
> >

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message