This is my regex originally from VB.
using System.Text.RegularExpressions;
#region "Regex"
public object preg_match(System.Object sRegex, System.Object sHaystack)
{
// Declare some varis
MatchCollection Matches = default(MatchCollection);
// My Regex to match some text. It is actually a whole <div> block.
Regex TheRegex = new Regex("sRegex");
// Get the Source code from the page
string t = sHaystack.ToString();
// Perform the match
Matches = TheRegex.Matches(t);
// Match for 1
Match Match = default(Match);
Match = TheRegex.Match(t);
// Search for all the words in a string
Match AllMatches = default(Match);
int iCount = 0;
int iResult = 0;
int iMaxResults = 0;
// Loop through the matches to store in an array
// From using PHP my whole existance, I like to have the
// Matches in an array
if (!Match.Success) {
string[,] aRes = new string[1, 1];
aRes[0, 0] = "";
return aRes;
}
string[,] aResults = new string[Matches.Item(0).Groups.Count + 1, Matches.Count + 1];
foreach (AllMatches in Matches) {
iCount = 0;
// We have sub results we want to store.
foreach (Group blah in AllMatches.Groups) {
aResults[iCount, iResult] = blah.Value;
iCount += 1;
}
if (iMaxResults < iResult) {
iMaxResults = iResult;
}
iResult += 1;
}
aResults[iCount, 0] = iMaxResults.ToString() + 1;
return aResults;
}
#endregion
The Part with errors
string[,] aResults = new string[Matches.Item(0).Groups.Count + 1, Matches.Count + 1];
foreach (AllMatches in Matches)