Regex to get port number

I have .config file I wanna dynamically get the regex value. Regex to get the port value in the example above. this config file is the config file of the robot stream.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
  <appSettings>
    <add key="port" value="8080" />
  </appSettings>
</configuration>

I wanted to get the value 8080

Hi,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(yourString,"(?<=\<add\s+key=""port""\s+value="")\d+(?=""\s+/\>)|(?<=\<add\s+value="")\d+(?=""\s+key=""port""\s*/\>)").Value

Note: It might be better to use deserialize XML than regex.

Regards,

1 Like