Need Regular Expressions help with my expression

simpleonline12

New member
Sep 29, 2009
191
3
0
I have a string of text that I am trying to match in my application.
This is the series that I am matching

//images.slashdot.org/hc/45/7ee10c139d5a.jpg

The only constant is going to be the amount of digits between the first two backslashes but then the actual jpg can vary.
I've tried this but I am not able to grab anything.
/hc/45/b6ffeb799a4e.jpg
\/\/images\.slashdot\.org\/[a-zA-Z0-9]\/[a-zA-Z0-9]\/[a-zA-Z0-9]\.jpg
Any ideas on where my expression is going wrong?
 


Is this in PHP? preg_match

first of all, don't have forward slash as a regex delimiter, use #. so you don't have to escape all the slashes
 
also, after your character clasees, you're not specifying how many matches you want so it'll only work if there's one and one only
PHP: Repetition - Manual

this regex will only match 2 and 2 only alpha-numeric characters after the first and second backslashes. are you sure the image filename is only alpha-numeric? could there be underscores?

Code:
#//images\.slashdot\.org/[a-zA-Z0-9]{2}/[a-zA-Z0-9]{2}/[a-zA-Z0-9]+\.jpg#
 
This is actually in VB.Net

I'm coming up with an error of "Object reference not set to an instance of an object."

This may be easier for me this way. What would be the RegEx to grab anything and everything between two backslashes like this /everythinghere/

I know there is some sort of wild card like an * or a way to say anything in between the backslashes I want to grab it regardless of what is it is.

Thanks again guys.
 
If you're getting a NullReferenceException then the regular expression is not the problem. For example, in the following code:

Code:
foo.bar()

If foo is null, then you'll get an exception. Look outside the regular expression code and you'll find your error.
 
Okay so I've tried all the advice given and I still don't get the result. Here is my actual code toggled to my button.

Code:
[FONT=Verdana][COLOR=white]PrivateSub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]Dim request As HttpWebRequest = HttpWebRequest.Create(URLofSite.Text)[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]Dim response As HttpWebResponse[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]response = CType(request.GetResponse, HttpWebResponse)[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]Dim webstream As Stream = response.GetResponseStream[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]Dim streamreader AsNew StreamReader(webstream, Encoding.UTF8)[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]Dim html AsString = streamreader.ReadToEnd[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]sourcecode = html.ToString[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]SourceViewer.Text = sourcecode.ToString[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]Dim sitekey AsString[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]Dim value AsString = RawCaptcha.Text[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]Dim m As Match = Regex.Match(SourceViewer.Text, CaptchaFinal.Text, RegexOptions.IgnoreCase)[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]If (m.Success) Then[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]Dim key AsString = m.Groups(1).Value[/COLOR][/FONT]
[FONT=Verdana][COLOR=white]sitekey = (key.ToString)[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]EndIf[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]Dim mymove AsString = "http:" & sitekey.ToString[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]MessageBox.Show(mymove.ToString)[/COLOR][/FONT]
 
[FONT=Verdana][COLOR=white]EndSub[/COLOR][/FONT]


Here is my app in action.

o53j4i.jpg