正则表达式字符串替换(Regular expression String replacement.)

编程入门 行业动态 更新时间:2024-10-27 20:37:00
正则表达式字符串替换(Regular expression String replacement.)

我有以下几行:

d:\Projects\qqq\Development\qqq.MySol1.sln d:\Projects\qqq\qqqDevelopment\qqqMySol2.sln d:\Projects\qqq\Development\MyInstaller.sln d:\Projects\qqq\qqq\Development\MyInstaller.sln d:\Projects\Development\MyInstaller.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 。 我一直在尝试使用The Regulator,并有一个部分解决方案:

.*\\(?<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}应该以某种方式修复。

I have the following lines:

d:\Projects\qqq\Development\qqq.MySol1.sln d:\Projects\qqq\qqqDevelopment\qqqMySol2.sln d:\Projects\qqq\Development\MyInstaller.sln d:\Projects\qqq\qqq\Development\MyInstaller.sln d:\Projects\Development\MyInstaller.sln

I need an regular expression that will result in name captures:

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

So a regex that will remove (ignore) the word qqq from the lines. I've been trying with The Regulator, and have a partial solution:

.*\\(?<A>.*)\\.{3}(?<B>.*)

This results in:

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

So the .{3} should be fixed somehow.

最满意答案

我认为应该有效:

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

I think that should work:

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

更多推荐

本文发布于:2023-08-01 10:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1357899.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   正则表达式   Regular   replacement   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!