A.M. D.
A.M. D.

Reputation: 928

Can a negative lookbehind be used in Phing replaceregexp task?

Having tried to drop a negative lookbehind regex into a Phing replaceregexp task and receiving the error:

BUILD FAILED
Error reading project file [wrapped: C:\path\to\build.xml:110:29: > required]
Total time: 0.4800 seconds

I see that the angle-bracket's a problem in the xml. Is there a way to specify a negative lookbehind regex in a build file, or is this something for a custom task?

My aim was to rename references in files to ".js" while leaving all extant '.min.js' references alone using something not unlike:

(<script)(.*)(src=\")(.*)(?<!\.min)(\.js\")

Upvotes: 0

Views: 169

Answers (1)

A.M. D.
A.M. D.

Reputation: 928

Dropping the regex into a properties file:

minify_path_regex=(<script)(.*)(src=\")(.*)(?<!\.min)(\.js\")

and then referencing:

<copy todir="${builddir}/custom_errors" >
    <filterchain>
        <replaceregexp>
            <regexp pattern="${minify_path_regex}" replace="\1\2\3\4.min\5" />
        </replaceregexp>
    </filterchain>
    <fileset refid="allPages" />
</copy>

But if there's a way to circumvent the xml/bracket problem inline I'd still love to know.

Upvotes: 1

Related Questions