[HELP] Regex ... regular expression really is my nemisis!

carlx

Registered Member
Joined
Dec 28, 2008
Messages
95
Reaction score
88
I have always hated regex and i just cant seem to get a working expression to grab the information i want! Help would be greatly appreciated!

The HTML code i am trying to grab:
Code:
                    <p>Ending:
                        25 Mar 12
                    </p>

I want to grab the date "25 Mar 12" and not have any whitespace with it. ... multiline regex just doesnt seem to like me at all and i have been playing with it for an hour now!

If you can help me out, that would be awesome! ... also anybody have a "idiots guide to regex" that they could direct me to, i need to learn it.... but i hate it so much!
 
Last edited:
(?<=Ending\:\r)\d{2}\s.*\s\d{2}(?=\r\<\/p\>)


maybe?
 
Nope, that isn't grabbing anything :(
 
works with .net i don't know enough about other languages and regex sorry
 
I'm working in .Net and its not returning anything! ... i've had enough of this bloody regex!
 
Then try

(?<=Ending\:\r)\d{2}\s.*\s\d{2}\r(?=\<\/p\>)

You can test them at
Code:
http://gskinner.com/RegExr/
 
Code:
Dim ResultString As String
Try
	ResultString = Regex.Match(SubjectString, "<p>Ending:\r\n(.*+)\r\n</p>", RegexOptions.Multiline).Groups(1).Value
Catch ex As ArgumentException
	'Syntax error in the regular expression
End Try

Code:
string ResultString = null;
try {
	ResultString = Regex.Match(SubjectString, "<p>Ending:\\r\\n(.*+)\\r\\n</p>",
		RegexOptions.Multiline).Groups[1].Value;
} catch (ArgumentException ex) {
	// Syntax error in the regular expression
}

Without dot matching new line.
 
I had this problem, its the new line character replace it with ""

or use the getstringinbetween function thats floating around, I remember someone already posted it in the vb section , or ive got an example one if you need it.
 
I do appologise, it was my mistake!

The code pasted in the origional post has no white spaces, the actualy code can be found here:
HTML:
http://www.competitions-time.co.uk/Computers-Comps/Win-Dell-XPS-15Z-Laptop-3540
- see the source code's formatting (i don't want to paste it again and make another mistake)
 
Still cant get this to work! going to sleep or im going to shoot somebody!
 
Give this a try, should solve your problem.

Code:
(\d{2}\s\w{3}\s\d{2})(</p>)

You want to grab $1
 
As for learning RegEX, I would recommend the O'Reilly book and getting RegEX Buddy. Both are invaluable, but still most people are never very good at RegEX that attempt to learn it.
 
Thank you, i certainly need to learn it because it is crucial for a lot of things i do, until now i've always managed to get it working, but yours did the trick, perfect first time!

+Rep & Thanks given.
 
VB

Code:
Dim ResultString As String
Try
	ResultString = Regex.Match(SubjectString, "<p>\s*Ending:\s*(.*)\s+</p>").Groups(1).Value
Catch ex As ArgumentException
	'Syntax error in the regular expression
End Try

C#

Code:
string ResultString = null;
try {
	ResultString = Regex.Match(SubjectString, "<p>\\s*Ending:\\s*(.*)\\s+</p>").Groups[1].Value;
} catch (ArgumentException ex) {
	// Syntax error in the regular expression
}
 
Back
Top