-3

我有包含以下字符串的文本文件:

coordsys = "Z:/SatData/Satimages/Project/Mtsat/mtsat-2r/nrl/NW-Pacific/Geo-Color/Project/201108170432_DAY1.jp2"
coordsys = "Z:/SatData/Satimages/Project/Mtsat/mtsat-2r/nrl/NE-Pacific/Geo-Color/Project/201208170432_NGT1.jp2"
coordsys = "Z:/SatData/Satimages/Project/kalpana/images/Geo-Color/Project/201108170432_DAY1.jp2"
img = ".jp2"

我只需要在以“coordsys”开头的字符串中将扩展名从 jp2 更改为 img,而不是其他任何字符串。例如 img = ".jp2" 应保持 img = ".jp2",但所有其他字符串应变为:

coordsys = "Z:/SatData/Satimages/Project/Mtsat/mtsat-2r/nrl/NW-Pacific/Geo-Color/Project/201108170432_DAY1.img"
coordsys = "Z:/SatData/Satimages/Project/Mtsat/mtsat-2r/nrl/NE-Pacific/Geo-Color/Project/201208170432_NGT1.img"
coordsys = "Z:/SatData/Satimages/Project/kalpana/images/Geo-Color/Project/201108170432_DAY1.img"

我怎么能用正则表达式做到这一点?

4

1 回答 1

0

全部替换(coordsys)(.*)(\.jp2)$1$2.img

于 2013-01-21T12:22:02.600 回答