cheatcountry

if I wanted to search for a stock symbol would this be the right way to do it

[][A-Z]|[A-Z]|[A-Z]|[A-Z]|[A-Z][]


Re: Regular Expressions searching for a stock symbol

Gunjan246

What is a stock symbol Can you give an example of it....

if you are checking only for a series of 5 characters then [A-Z]{5}

or if you want 0 or more times then u can use [A-Z]*

or if you want 1 or more times then u can use [A-Z]+

Gunjan






Re: Regular Expressions searching for a stock symbol

cheatcountry

A stock symbol is like GOOG or MSFT or something like that




Re: Regular Expressions searching for a stock symbol

cheatcountry

Gunjan246 wrote:

What is a stock symbol Can you give an example of it....

if you are checking only for a series of 5 characters then [A-Z]{5}

or if you want 0 or more times then u can use [A-Z]*

or if you want 1 or more times then u can use [A-Z]+

Gunjan



It can be anything from 1-5 characters...




Re: Regular Expressions searching for a stock symbol

cheatcountry

This is my current code but it doesn't work:

StringBuilder url = new StringBuilder();
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string B;
string C;
string D;
string E;
string F;
string G;
string H;
string I;
string J;
string K;
string L;
string M;
string N;
string O;
for (int i = 0; i < alphabet.Length; i++)
{
url.Append("http://www.poweropt.com/optionable.asp fl=");
url.Append("A");
string urlstring = url.ToString();
string pattern = @"[/s][ext]|[A-Z]|[A-Z]|[A-Z]|[A-Z][/s]";
Regex test = new Regex(pattern, RegexOptions.Multiline);
WebRequest wr;
WebResponse wresponse;
StreamReader sr;
string content;
wr = HttpWebRequest.Create(urlstring);
wresponse = wr.GetResponse();
sr = new StreamReader(wresponse.GetResponseStream());
content = sr.ReadToEnd();
sr.Close();
if (content.Contains(pattern))
{
MessageBox.Show("Success!");
}
else
{
MessageBox.Show("Failure!");
}




Re: Regular Expressions searching for a stock symbol

Gunjan246

1-5 characters then i will suggest [A-Z]{1,5}

Gunjan






Re: Regular Expressions searching for a stock symbol

cheatcountry

Gunjan246 wrote:

1-5 characters then i will suggest [A-Z]{1,5}

Gunjan



Well I also want the first letter to match the current letter that it is searching for which in the current code is A




Re: Regular Expressions searching for a stock symbol

Gunjan246

string pattern = var + @"[A-Z]{1,5}";






Re: Regular Expressions searching for a stock symbol

cheatcountry

Gunjan246 wrote:
string pattern = var + @"[A-Z]{1,5}";



I changed that line to string pattern = "A" + @"[A-Z]{0,4}"; and it is still not working




Re: Regular Expressions searching for a stock symbol

Gunjan246

your code wont give u the desired result as you told me earlier because your pattern string is incorrect

x|y

Matches either x or y. For example, "z|food" matches "z" or "food". "(z|f)ood" matches "zood" or "food".

Gunjan






Re: Regular Expressions searching for a stock symbol

cheatcountry

Gunjan246 wrote:

your code wont give u the desired result as you told me earlier because your pattern string is incorrect

x|y

Matches either x or y. For example, "z|food" matches "z" or "food". "(z|f)ood" matches "zood" or "food".

Gunjan



I said previously that I changed my pattern string to what you gave me.





Re: Regular Expressions searching for a stock symbol

Gunjan246

In your code I would replace

string pattern = @"[/s][ext]|[A-Z]|[A-Z]|[A-Z]|[A-Z][/s]";
by

string var = "A";

string pattern = @"\s" + var + "[A-Z]{0,4}\s";

and replace

if (content.Contains(pattern))
{
MessageBox.Show("Success!");
}
else
{
MessageBox.Show("Failure!");
}

by

if (Regex.IsMatch(content, pattern, RegexOptions)
MessageBox.Show("Success!");
else
MessageBox.Show("Failure!");






Re: Regular Expressions searching for a stock symbol

Gunjan246

string var = "A";

string pattern = @"\s" + var + "[A-Z]{0,4}\s";

WebRequest wr;
WebResponse wresponse;
StreamReader sr;
string content;
wr = HttpWebRequest.Create(urlstring);
wresponse = wr.GetResponse();
sr = new StreamReader(wresponse.GetResponseStream());
content = sr.ReadToEnd();
sr.Close();
if (Regex.IsMatch(content, pattern, RegexOptions.Multiline)
MessageBox.Show("Success!");
else
MessageBox.Show("Failure!");






Re: Regular Expressions searching for a stock symbol

Gunjan246

I hope this post was helpful to you .... If yes please mark it as helpful






Re: Regular Expressions searching for a stock symbol

cheatcountry

How would I put the info that it finds into a text file