我在名为 build.xml 的文件中有以下文本:
component.rollup=true
component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml
component.rollup_dir=/base
我希望它在其中添加一个文件,这样它将变成:
component.rollup=true
component.rollup.modules.buildfiles=io-base.xml, io-form.xml, io-xdr.xml, io-extended.xml
component.rollup_dir=/base
我如何使用正则表达式做到这一点?
我正在使用 javascript。
谢谢!
编辑:
忘了告诉你文件不是静态的,它们可能会改变。只有
component.rollup.modules.buildfiles=
永远在那里。
最佳答案
假设您已经阅读了文件的内容:
fileContents.replace(
/^(component\.rollup\.modules\.buildfiles\s*=.*)$/m,
'$1, io-extended.xml');
关于javascript - 帮助用正则表达式替换文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6302093/