im trying to extract a substring with regex but im having some troubles...
The string is build from a columns of strings and i need the the 4th column only
string stringToExtractFrom = "289 120 00001110 ??
4Control@SimApi@@QAEAAV01@ABV01@@Z = ??4Control@SimApi@@QAEAAV01@ABV01@@Z
(public: class SimApi::Control & __thiscall SimApi::Control::operator=(class
SimApi::Control const &))"
string pattern = @"\s+\d+\s+\d+\s+\S+\s(.*)\=";
RegexOptions options = RegexOptions.Multiline;
Regex regX = new Regex(pattern, options);
Match m = regX.Match(stringToExtractFrom);
while (m.Success)
{
Group g = m.Groups[1];
defData += g+"\n";
m = m.NextMatch();
}
this is the wanted string: ?? 4Control@SimApi@@QAEAAV01@ABV01@@Z
with the string below it worked when i got the substring i want as a group
1 0 00002E00 ??0ADOFactory@SimApiEx@@QAE@ABV01@@Z = ??0ADOFactory@SimApiEx@@QAE@ABV01@@Z (public: __thiscall SimApiEx::ADOFactory::ADOFactory(class SimApiEx::ADOFactory const &))
If the second string works for you and the first one does not, you might first match 1+ digits and use \\S+
for the third part. Then use a negated character class to capture matching not an equals sign:
\d+\s+\d+\s+\S+\s+([^=]+) =
See a .NET regex demo | C# Demo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.