Regular expressions are something I often struggle with. I can usually draw the state machine which represents the regular expression, but to translate it to a regular expression is sometimes a hard task.
Today I wanted to write a regular expression to check whether a certain tag is between the head tags of a HTML document. The regular expression itself was not difficult, but as I forgot the s modifier it took quite a while to make it work…
Anyway, here is the pattern:
$this->assertPattern('#<head>(.)*<link rel="xy" href="some_url" />(.)*</head>#s', $html);