站长资讯网
最全最丰富的资讯网站

正则表达式的字符串替换方法

我有以下几行:

d:ProjectsqqqDevelopmentqqq.MySol1.sln
d:ProjectsqqqqqqDevelopmentqqqMySol2.sln
d:ProjectsqqqDevelopmentMyInstaller.sln
d:ProjectsqqqqqqDevelopmentMyInstaller.sln
d:ProjectsDevelopmentMyInstaller.sln

我需要一个正则表达式,这将导致捕获:

Line 1: Development and MySol1.sln
Line 2: Development and MySol2.sln
Line 3: Development and MyInstaller.sln
Line 4: Development and MyInstaller.sln
Line 5: Development and MyInstaller.sln

因此,一个正则表达式,将删除(忽略)字qqq从行。 我一直在试图与调节,并有部分的解决方案:

复制代码 代码如下:
.*\(?<A>.*)\.{3}(?<B>.*)

这导致:

Line 1: Development and .MySol1.sln
Line 2: qqqDevelopment and MySol2.sln
Line 3: Development and nstaller.sln
Line 4: Development and nstaller.sln
Line 5: Development and nstaller.sln

因此,.{3}应固定

1.我认为,应该工作:

.*\(?:qqq)?(?<A>.*)\(?:qqq)?(?<B>.*)

赞(0)
分享到: 更多 (0)
网站地图   沪ICP备18035694号-2    沪公网安备31011702889846号