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

4
  • 2
    Why are you using a regex? Does your language not have proper XML support? Commented Mar 12, 2015 at 23:40
  • It looks like part of a .net config file... there are tools out there to parse and process it... use them. Commented Mar 12, 2015 at 23:43
  • Just an fyi, don't use regex for xml parsing. Commented Mar 12, 2015 at 23:43
  • My aim was to do a simple string replace then get involved in xml Commented Mar 12, 2015 at 23:47

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.