Page 1 of 1

RegEX Help

Posted: Wed May 13, 2009 6:18 pm
by shortaug
I have an array of lines.

ex:
02/05/2009,12:, [sbh\dekk44] Test [Who Boss] weeekddseee:
4/3/2003,12:, [ahell] Test [Who Boss] weeekddseee:

I need to draw out the string within the [ ] as long as they:
  • have sbh\ or no sbh\
    have no white space within the [ ]
    can be any length greater than 1
    can contain any number of numbers or letters
In the example above, only the sbh\dekk44 and ahell are what I want.

Currently, I have:
preg_match("#\[(\w+)\]#i", $line, $matches)

It correctly matches ahell, but I cannot figure out how to match the sbh\ or it's lack thereof.

Any help?

Re: RegEX Help

Posted: Wed May 13, 2009 6:22 pm
by shortaug
heh, figured it out just a few seconds later:

preg_match("#\[((sbh.)?\w+)\]#i", $line, $matches)