public static string GetConfigFileNameFromCurrentLine(this DTE dte) { string moduleName = null; var configRegex = new Regex(@"configFile=([""'])(?:(?=(\\?))\2.)*?\1"); var regex = new Regex(@"([""'])(?:(?=(\\?))\2.)*?\1"); var line = dte.GetLineText(); Match match = configRegex.Match(line); if (!match.Success) { match = regex.Match(line); } if (match.Success) { moduleName = (from object capture in match.Groups select capture.ToString().Replace(@"""", "")).FirstOrDefault(); moduleName = moduleName.Replace("configFile=", ""); if (moduleName != null && !moduleName.EndsWith(".config") && !moduleName.EndsWith(".xml")) { moduleName += ".config"; } } return(moduleName); }
public static string GetTextBetweenQuatationsFromSelectionOrCurrentLine(this DTE dte) { var regex = new Regex(@"([""'])(?:(?=(\\?))\2.)*?\1"); string moduleName = null; TextSelection txtSel = (TextSelection)dte.ActiveDocument.Selection; Match match = regex.Match(txtSel.Text.Trim()); if (!match.Success) { match = regex.Match(dte.GetLineText()); } if (match.Success) { moduleName = (from object capture in match.Groups select capture.ToString().Replace(@"""", "")).FirstOrDefault(); } return(moduleName); }