Alan is right to take stock, use /<head([\s\S]*)\/head>/ , and he should do what you want.
The actual regex that I would use for the job is /<head>([\s\S]*?)<\/head>/ , but the difference will probably not matter, as it just ensures that there is no greedy matching with the 2nd heading, which should never be :)
source share