You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Steve Amerige <St...@sas.com> on 2011/11/09 21:40:38 UTC

Negative Lookahead and Regexp

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:

     http://www.regular-expressions.info/lookaround.html

Thanks for any assistance!

Enjoy,
Steve Amerige
SAS Institute, Deployment Software Development


Re: Negative Lookahead and Regexp

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-11-10, Steve Amerige wrote:

> <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>

your first three properties

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

All Ant properties except for those that start with a.b.

> <propertyset id="union">
> <propertyset refid="minus"/>
> <propertyset refid="plus"/>
> </propertyset>

All Ant properties including the ones that start with a.b as they are
part of the plus set.

> If what I'm looking to find is "^a\.(?!b\.).*" ("a." followed by
> anything except for "b."), then this doesn't work.

<propertyset id="r"><propertyref regex="^a\.(?!b\.).*"/></propertyset>

contains just a.c.x.y for me.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Negative Lookahead and Regexp

Posted by Steve Amerige <St...@sas.com>.
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>
<echoproperties>
<propertyset>
<propertyset refid="union"/>
</propertyset>
</echoproperties>
</target>

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?

Enjoy,
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.
> http://ant.apache.org/manual/Types/propertyset.html
>
> ------------------------------------------------------------------------------------------------------------------------------------
> *From:* Steve Amerige <St...@sas.com>
> *To:* Ant Users List <us...@ant.apache.org>
> *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:
> >
> > http://www.regular-expressions.info/lookaround.html
>
>
>


Re: Negative Lookahead and Regexp

Posted by Vimil Saju <vi...@yahoo.com>.
The propertyset type has a negate attribute. maybe that will help you.
http://ant.apache.org/manual/Types/propertyset.html



________________________________
From: Steve Amerige <St...@sas.com>
To: Ant Users List <us...@ant.apache.org>
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:
>
> http://www.regular-expressions.info/lookaround.html

Re: Negative Lookahead and Regexp

Posted by Steve Amerige <St...@sas.com>.
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:
>
> http://www.regular-expressions.info/lookaround.html


Re: Negative Lookahead and Regexp

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-11-09, Steve Amerige wrote:

> Is negative lookahead supported at all in Ant 1.7 and higher
> (Ant-Contrib, too)?  Maybe my syntax is off:

In general regex suppprt in Ant (not sure about Antcontrib) is provided
by a pluggable implementation so the question is whether said
implementation supports it.  In your case the implementation most likely
is java.util.regex which claims to support negative lookahead using the
same syntax you use.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org