I need regular expression to remove duplicate using statements.
using NS.SN.Services.Common;
using NS.SN.Data.BaseRegistry;
using NS.SN.Data.DataContracts.Registry;
using NS.SN.Services.Common; <-- this one must go
using NS.SN.Services.DataContracts;
using System;
using System.Collections.Generic;
using System.Transactions;
using CodeEnums = NS.SN.Data.DataContracts.Enums.CodeEnums;
using System.Linq;
Problem is that this reg-开发者_JAVA百科exp does not work because ([.:b]*\n)* matches only first new-line char. Can I fix this reg-exp?
{:b*using:bNS.SN.Services.Common;([.:b]*\n)*}using:bNS.SN.\Services.\Common;:b*\n
Use this as "Find what":
{:b*using:bNS\.SN\.Services\.Common;(.*\n)*}using:bNS\.SN\.Services\.Common;:b*\n
and this as "Replace with":
\1
UPDATE:
I completely missed the dot inside the character group:
[.:b]*
will match the dot or the colon or the letter b, because it is inside a character class! What you meant is (.|:b)*
, where the :b
is redundant, because it is contained inside "any character" (.
), so it simply should be .*
. See the updated regex above.
精彩评论