1

I have the below xml on a single line, I want to get the string of DBB and replace it using regex

<Configuration ConfiguredType="Property" Path="\Package.Connections[DBA DB].Properties[ConnectionString]" ValueType="String"><ConfiguredValue>Data Source=.\test;Initial Catalog=DBA;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=B;</ConfiguredValue></Configuration><Configuration ConfiguredType="Property" Path="\Package.Connections[DBB DB].Properties[ConnectionString]" ValueType="String"><ConfiguredValue>Data Source=.\test;Initial Catalog=DBB;Provider=SQLNCLI10.1;Integrated Security=SSPI;Auto Translate=False;Application Name=C;</ConfiguredValue></Configuration></DTSConfiguration>

I have the following which works on multi line xml but not this single line example

Data Source=.+?(?=[a-z])*\;Initial Catalog=DBB;(.*?)Integrated(.*?)[^;]*;

The above regex highlights both DBA and DBB and ends there.

Could you help in finding the missing piece in the regex I have created

FreshRob
  • 363
  • 1
  • 3
  • 9

1 Answers1

1

Replace Data Source=.+? with Data Source=[^<]+? to avoid traversing the start of the tag.

aergistal
  • 29,947
  • 5
  • 70
  • 92
  • 1
    It's far from perfect, you should really use an XML parser if possible, for the sanity of the developers that might touch your code later. – aergistal Mar 12 '15 at 23:49