BYO Database pg 254 regular expression

Hi - I’m a newbie - so just getting started trying to understand regular expressions. I am confused about ta part of the reg expression on pg 254 of Kevin Yanks book i.e the reg expr for an URL. The part I need explaining is ([[1]+) - described as saying ‘one or more characters, none of which is an opening bracket’ - see last paragraph on page.
With my limited knowledge I read it as saying 'one or more strings starting with a [ (i.e opening bracket) - that what I thought ^[ meant - where is the part that says ‘one or more characters’ , and ‘NOT starting with [’ ??
Sorry - I know what the book says must be right, but I just need some explanation as too how that reg. expr works!
Thanks!


  1. ↩︎

Hey pawnee,
It doesn’t look like you’re getting much of a response in the book forum so I’m going to move this thread over to the PHP forum.

Inside a character class the caret means “not”.
eg ^xy means starts with xy, while x[^y] means an x followed by something that’s not a y

Here is ([[2]+) broken down into its component parts

( - start of capture group
[ - start of character class
[3] - close of character class

  • match one or more of the previous (character class)
    ) - close capture group

The ^ caret at the start of a character class turns it into a negated character class. See character classes

The + means to match one or more characters. See repetition


  1. ↩︎

  2. ↩︎

  3. - any character that is not a left square bracket
    ↩︎