[thelist] pcre regex in php

throwaway at gmontague.co.uk throwaway at gmontague.co.uk
Tue Sep 23 06:03:28 CDT 2003

Hi all,
   I seem to be having a brain block with the following regex....

I'm trying to extract all the text between [cn][/cn] 'tags' in a document.
For example,

$description = "[cn]Clio Gould, Edmund Coxon, Jeremy Morris, Stephen Morris,
Katie Hull[/cn]"

$regex = "\[cn\]([^(?:\/[cn\])]){1,}";
preg_match_all("/$regex/", $description, $matches);

Which I expected to work, but what I get is

"Clio Gould, Edmu"

because (I think) the second part of the regex is treating the 'cn' as part
of a set so I'm hitting the 'n' in Edmund and dropping out. I've looked
though the docs about this but I can't seem to correct it. Any help would
be appreciated.


More information about the thelist mailing list