Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Reg Ex help

  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reg Ex help

    Hello,

    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)
    Last edited by pvt_ben; 04-01-2010 at 05:08 AM.

  • #2
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hopeful bump

  • #3
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Last bump. ;_;

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You can limit the length so:

    Code:
    ([a-zA-Z\' ]{24})
    The other two conditions are less easy to achieve. Google for 'pcre cheat sheet'. It'll give you some quick pointers on look ahead/behind assertions etc to play around with.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •