You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Rebhan, Gilbert" <Gi...@huk-coburg.de> on 2005/01/28 12:19:56 UTC

regexp question

Hi,

scenario = a txtfile where i have to put a value in.

The line where that value should go is always line number 26 of
that file. line number 26 is always blank and should contain the
value after transformation.

I've tried with :

<property name="br" value="${line.separator}" />
<property name="insert" value="hello world" />


<copy file="${txtfile}" tofile="modified.txt">
    <filterchain>
        <tokenfilter>
            <filetokenizer />
                <replaceregex
pattern="(.*${br}{25})(${br}.*)"
                      replace="\1${insert}\2" />
        </tokenfilter>
    </filterchain>
</copy>

The script runs, but the file stays the same.
Must be a logical error in the regex syntax.

(.*${br}{25})(\s${br})

group 1 = any sign, one or more, followed by linebreak, 25x (= 25 lines)
group 2 = the next (blank) line

replace \2 = replace group 2 with ${insert}

Where do i go wrong ? Don't know exactly how to write the replace part.
My regexengine is the java builtin (1.4.2_05)

Thanks for any hint !

Gilbert

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


Re: regexp question

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi, Nat

i considered concat ... already, but i felt like
there would be a more elegant and shorter solution
with regular expressions.

I'm sure there's one, but i'm no expert for regexp.

Gilbert

> Why not use concat with a filterchain/headfilter?
> Basically you read (with headfilter lines=25) the first 25 lines, concat 
> the 26th line, then again using the headfilter this time skipping the 
> blank line.  The point is that concat can append any text string, not 
> only the contents of files.
> my $0.02
> -nat



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


Re: regexp question

Posted by Nat Gross <na...@verizon.net>.
Rebhan, Gilbert wrote:

>Hi,
>
>scenario = a txtfile where i have to put a value in.
>
>The line where that value should go is always line number 26 of
>that file. line number 26 is always blank and should contain the
>value after transformation.
>
>I've tried with :
>
><property name="br" value="${line.separator}" />
><property name="insert" value="hello world" />
>
>
><copy file="${txtfile}" tofile="modified.txt">
>    <filterchain>
>        <tokenfilter>
>            <filetokenizer />
>                <replaceregex
>pattern="(.*${br}{25})(${br}.*)"
>                      replace="\1${insert}\2" />
>        </tokenfilter>
>    </filterchain>
></copy>
>
>The script runs, but the file stays the same.
>Must be a logical error in the regex syntax.
>
>(.*${br}{25})(\s${br})
>
>group 1 = any sign, one or more, followed by linebreak, 25x (= 25 lines)
>group 2 = the next (blank) line
>
>replace \2 = replace group 2 with ${insert}
>
>Where do i go wrong ? Don't know exactly how to write the replace part.
>My regexengine is the java builtin (1.4.2_05)
>
>Thanks for any hint !
>
>Gilbert
>
>  
>
Why not use concat with a filterchain/headfilter?
Basically you read (with headfilter lines=25) the first 25 lines, concat 
the 26th line, then again using the headfilter this time skipping the 
blank line.  The point is that concat can append any text string, not 
only the contents of files.
my $0.02
-nat

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