You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Gr...@aviall.com on 2012/01/06 22:11:34 UTC

Advanced Regexp Question

Hello,

I am able to do some very simple regexp replacement with the replaceregexp 
ant task but now need to do something a little more advanced.

Say I have a string in a file like this:

        require(["a","foo/b","foo/c"], function(){...})

What I want to do is replace all the "foo" with "bar" so the final product 
looks like this:

        require(["a","bar/b","bar/c"], function(){...})

With replaceregexp the best I've been able to get was below using regexp 
like "require\(\s*\[(.*)foo/([^\]]*)\]"

        require(["a","foo/b","bar/c"], function(){...}) 

(I can't just do a global replace on "foo" because I only want to do the 
replacement in this "require" context.)

Any ideas?

Thanks for any advice,
Greg

"If I had asked my customers what they wanted, they would have said 'A 
faster horse'" -- Henry Ford

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
_

This e-mail message, including attachments, may contain confidential, 
proprietary, or export controlled information.
Any unauthorized disclosure, distribution, or other use is prohibited, 
unless expressly authorized. 
If you receive this e-mail in error, please notify the sender, and delete 
all copies of the original message from your systems.

Re: Advanced Regexp Question

Posted by "Scot P. Floess" <sf...@nc.rr.com>.
I could be wrong, but my guess is he wants this first pass (I suppose 
because that's what I'd want)...

The only problem with twice is...it doesn't address what happens if there 
is a third, fourth and fifth (and so on) references...

On Sun, 8 Jan 2012, Andy Stevens wrote:

> On 6 Jan 2012 21:12, <Gr...@aviall.com> wrote:
>> Say I have a string in a file like this:
>>
>>        require(["a","foo/b","foo/c"], function(){...})
>>
>> What I want to do is replace all the "foo" with "bar" so the final product
>> looks like this:
>>
>>        require(["a","bar/b","bar/c"], function(){...})
>>
>> With replaceregexp the best I've been able to get was below using regexp
>> like "require\(\s*\[(.*)foo/([^\]]*)\]"
>>
>>        require(["a","foo/b","bar/c"], function(){...})
>>
>> (I can't just do a global replace on "foo" because I only want to do the
>> replacement in this "require" context.)
>>
>> Any ideas?
>
> Run your regexp over the file twice? Second pass will catch the foo that
> was left over the first time.
>
> Andy.
>

Scot P. Floess             RHCT  (Certificate Number 605010084735240)
Chief Architect FlossWare  http://sourceforge.net/projects/flossware
                            http://flossware.sourceforge.net
                            https://github.com/organizations/FlossWare

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


Re: Advanced Regexp Question

Posted by Andy Stevens <in...@googlemail.com>.
On 6 Jan 2012 21:12, <Gr...@aviall.com> wrote:
> Say I have a string in a file like this:
>
>        require(["a","foo/b","foo/c"], function(){...})
>
> What I want to do is replace all the "foo" with "bar" so the final product
> looks like this:
>
>        require(["a","bar/b","bar/c"], function(){...})
>
> With replaceregexp the best I've been able to get was below using regexp
> like "require\(\s*\[(.*)foo/([^\]]*)\]"
>
>        require(["a","foo/b","bar/c"], function(){...})
>
> (I can't just do a global replace on "foo" because I only want to do the
> replacement in this "require" context.)
>
> Any ideas?

Run your regexp over the file twice? Second pass will catch the foo that
was left over the first time.

Andy.

Re: Advanced Regexp Question

Posted by "Scot P. Floess" <sf...@nc.rr.com>.
Greg,

I've been looking at this for about an hour or so...

I'm stumped too ;)

On Fri, 6 Jan 2012, Greg.Zoller@aviall.com wrote:

> Hello,
>
> I am able to do some very simple regexp replacement with the replaceregexp
> ant task but now need to do something a little more advanced.
>
> Say I have a string in a file like this:
>
>        require(["a","foo/b","foo/c"], function(){...})
>
> What I want to do is replace all the "foo" with "bar" so the final product
> looks like this:
>
>        require(["a","bar/b","bar/c"], function(){...})
>
> With replaceregexp the best I've been able to get was below using regexp
> like "require\(\s*\[(.*)foo/([^\]]*)\]"
>
>        require(["a","foo/b","bar/c"], function(){...})
>
> (I can't just do a global replace on "foo" because I only want to do the
> replacement in this "require" context.)
>
> Any ideas?
>
> Thanks for any advice,
> Greg
>
> "If I had asked my customers what they wanted, they would have said 'A
> faster horse'" -- Henry Ford
>
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
>
> This e-mail message, including attachments, may contain confidential,
> proprietary, or export controlled information.
> Any unauthorized disclosure, distribution, or other use is prohibited,
> unless expressly authorized.
> If you receive this e-mail in error, please notify the sender, and delete
> all copies of the original message from your systems.

Scot P. Floess             RHCT  (Certificate Number 605010084735240)
Chief Architect FlossWare  http://sourceforge.net/projects/flossware
                            http://flossware.sourceforge.net
                            https://github.com/organizations/FlossWare

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