0

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 &))

1
  • Maybe Regex.Match(stringToExtractFrom, @"\B\?\?\S*").Value will do? Commented Mar 17, 2019 at 14:08

1 Answer 1

1

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

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

2 Comments

@lior The columns are divided by the whitespace right? What is green in the regex101 link is the first capturing group regex101.com/r/Iaks6D/3
Yes, this is the only way i could get the column i wanted.. Im sure there is a better way to get it as the match and not group

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.