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)

What errors are you getting?

Try using this

string[,] aResults = new string[Matches[0].Groups.Count + 1, Matches.Count + 1];

Didn't test it, but it could point you to the right direction
Regards

It fixed one error...

No.1 Error for the in

Error	6	Type and identifier are both required in a foreach statement	C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\iUltimate\iUltimate\Form3.cs	76	29	iUltimate

No.2 Error for the All Matches, what should of been definded already.

Error	7	The type or namespace name 'AllMatches' could not be found (are you missing a using directive or an assembly reference?)	C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\iUltimate\iUltimate\Form3.cs	76	18	iUltimate

Dont worry about No2 Its fixed.

Should you be supplying a type for allmatches?

Matches AllMatches
Regards

No, Please concentrate on Error No.1

Post what you have now. Maybe we could locate the problem.

Here you go

Error	2	Type and identifier are both required in a foreach statement	C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\iUltimate\iUltimate\Form3.cs	74	29	iUltimate

No I mean the whole code (recently updated).

I think there's a problem with how you did your foreach.

Regards

Oh ok

#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[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

Like i said on my earlier post,shouldn't you be supplying a type for allmatches?

foreach (Match match in Matches)

Like i said on my earlier post,shouldn't you be supplying a type for allmatches?

foreach (Match match in Matches)

Ok, thanks. That takes care of that problem.... Now I need to deal with using that regex. Here is a code that uses it

sTmp = web("http://www.samair.ru/proxy/" + tmpPages(1, iPg));
            tmp = preg_match("<tr><td>([^<]*?)<script\\ type=\"text/javascript\">document\\.write\\(\":\"([a-z\\+]*?)\\)", sTmp);

            if (string.IsNullOrEmpty(tmp(0, 0)) | tmp(0, 0) == null)
            {

            }

Every tmp has a error, sTmp, web. iPg, and tmpPages all have errors. They didn't in VB. Is there a system I am suppose to be using?

Do you mind showing us those errors? and providing us the other descriptions like what type are you using.

Regards

PS:

Best if you show us the whole code.

ok here lol

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Net.NetworkInformation;
using System.IO;
using System.Text.RegularExpressions;
using DevComponents.DotNetBar;


namespace iUltimate
{
    public partial class Form3 :  Office2007RibbonForm
    {
        int proxiesIterator = 0;
        public Form3()
        {
            InitializeComponent();

        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }
        
        #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[0].Groups.Count + 1, Matches.Count + 1];
        foreach (Match match 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

       
        


        private void buttonX1_Click(object sender, EventArgs e)
        {
            sTmp = web("http://www.samair.ru/proxy/" + tmpPages(1, iPg));
            tmp = preg_match("<tr><td>([^<]*?)<script\\ type=\"text/javascript\">document\\.write\\(\":\"([a-z\\+]*?)\\)", sTmp);

            if (string.IsNullOrEmpty(tmp(0, 0)) | tmp(0, 0) == null)
            {

            }
        }

        
    }
}

Anything Else?

Also for each proxy it gets I need to add it to a list box

Where did you declared this tmpPages, sTpm, iPg? :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.