我有一个类似的问题here,我能够解决。如果一个字符串包含字X,则只选择字Y
我需要的是一个字符串包含文字X,我希望能够说,如果这个字符串包含“azureStorage”选择只有一个字Y.
,然后选择“mystorage”
<add name="azureStorage" connectionString="DefaultEndpointsProtocol=https;AccountName=mystorage;AccountKey=myKey" />
我最近的东西是这个正则表达式,它适用于regex101,但不是在c#中。
(?<=(azureStorage)...................................................AccountName=).[^;]*
显然这不是一个好的解决方案。
Here is a link to the example on Regex 101
为什么使用regex10 1如果你需要一个.NET正则表达式? regex101不支持.NET语法和功能。在regexhero.net或regexstorm.net上测试。 –
而不是使用正则表达式,为什么不解析XML然后解析连接字符串? – juharr
为什么不使用'azureStorage。* AccountName =([^;] *)'并抓取捕获的组#1 – anubhava