View Full Version : Reg Ex help

04-01-2010, 04:48 AM

I'm new here, and I'm trying to wrap my head around Regular Expressions. I've read the PHP.net section on it, though most of it didn't make any sense to me, so I'm coming here. =)

I'd like to conder this line of text:
[ 2010.03.31 12:12:12 ] Blah Blah > This is some text.

I would like to extract the date information from the brackets, then the "Blah Blah" text before the ">" and after the "]", and then the rest of the text after the ">"

I'm really not sure how I would start off. I think I can get the last two matches, but it's the date that's throwing me off.

I'd apreciate any help. =)

EDIT: I think I got the date part downl; this seems to work:
#\[ ([0-9.: ]+) \]#

But now I'm having trouble with the second part. The second part should be A-Za-z0-9, can include 1 space, apostorpies (as long as they're not at the beginning or end), and is 24 characters long. I have this:
([a-zA-Z\' ]+)
But I have no idea how to restrict it to only one space or 24 characters max, or how I can assert that the apostropies are NOT at the beginning or end (eg: [ 2010.03.31 12:12:12 ] Bla'h Blah > This is some text. should work but [ 2010.03.31 12:12:12 ] 'Blah Blah > This is some text. shouldn't)

04-02-2010, 12:36 AM
Hopeful bump

04-03-2010, 06:29 PM
Last bump. ;_;

04-03-2010, 06:44 PM
You can limit the length so:

([a-zA-Z\' ]{24})

The other two conditions are less easy to achieve. :D Google for 'pcre cheat sheet'. It'll give you some quick pointers on look ahead/behind assertions etc to play around with.