Regex problem?
Feb 24, 2012 at 9:43pm UTC
Hi guys,
I need your help, I am using C++/CLI to code my program. I have got a problem with the regex pattern. I couldn't be able to extract the hyperlink from my php page while I find the matches pattern that I selected on the listview items.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
private : System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
for each (ListViewItem ^item in this ->listView1->CheckedItems)
{
try
{
String ^URL1 = "http://www.mysite.com/link.php?user=tester" ;
HttpWebRequest ^request1 = safe_cast<HttpWebRequest^>(WebRequest::Create(URL1));
HttpWebResponse ^response1 = safe_cast<HttpWebResponse^>(request1->GetResponse());
StreamReader ^reader1 = gcnew StreamReader(response1->GetResponseStream());
String ^str1 = reader1->ReadToEnd();
String ^pattern1 = item->Text + "(<p id='images'>(.*?)</p>)" ;
MatchCollection ^matches1 = Regex::Matches(str1, pattern1);
Match ^m1 = Regex::Match(str1, pattern1);
for each (Match ^x1 in matches1)
{
array<String^> ^StrArr1 = x1->Value->ToString()->Split();
String ^test = (URL1 + x1->Value->ToString());
MessageBox::Show(test);
}
}
catch (Exception ^ex)
{
}
}
}
I am definitely sure that the html tags has the correct tags name.
However, I have put the breakpoint in this line:
Match ^m1 = Regex::Match(str1, pattern1);
I can see the value for pattern1 so here it is:
"my strings 1<p id='images'>(.*?)</p>"
It have found the matches with the html tag, but it doesn't extract the id. So here's the html tags:
<p id="images" > <a href="images.php?id=1" >Images</a>
Do anyone know how I can extract the id in the images tags from the html source?
Any idea how I can do this?
Thanks in advance.
Feb 27, 2012 at 5:45pm UTC
3 days have passed and nobody have reply. do anyone know how to fix this?
Feb 29, 2012 at 2:08am UTC
please can someone help???????
Feb 29, 2012 at 7:42am UTC
Maybe with a regex like this (not tested):
images\.php\?id=([0-9]{1,}+)
Topic archived. No new replies allowed.