Help us to replace a text with regex

advertisements

I have the following text in a file called build.xml:

component.rollup=true
component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml
component.rollup_dir=/base

I want it to add one file in it so it will become:

component.rollup=true
component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml, io-extended.xml
component.rollup_dir=/base

How can I do that with regex?

I'm using javascript.

Thanks!

EDIT:

Forgot to tell you that the files are not static, they may change. Only

component.rollup.modules.buildfiles=

will always be there.


Assuming you have already read the contents of the file:

fileContents.replace(
  /^(component\.rollup\.modules\.buildfiles\s*=.*)$/m,
  '$1, io-extended.xml');