Reputation: 1127
Say you have a string
:
string s = "GameObject.Find(\"obj\").GetComponent(\"comp\").GetMethod(\"method\").Get...";
The string
can have any number of GetX()
methods appended to it.
And you need to separate each method without the "." separator. Although, GameObject.Find
can keep the (dot)
.
Here is my code so far :
Match match = Regex.Match(s, "(.+?\\(\".+?\"\\))(?:\\.??)*");
This produces only one group. What is the correct solution to this problem?
Edit :
Updated with non-capturing group.
Upvotes: 0
Views: 1347
Reputation: 838376
First I'd recommend using verbatim string literals for writing regular expressions in C#. This cuts down the number of backslashes you need to write.
@"(.+?\("".+?""\)\.??)*"
To get all the captures, inspect Match.Captures
.
See it working online: ideone
Upvotes: 1