Php正则表达式多行搜索问题

I am trying to get all characters between style tag. this is my regex

 '#<style>(.*?)</style>'

It is producing result correctly However it is not working for multi line

Working correctly for this :

<style>body { height: '100%'; }</style>

This is not working

<style> 
body { 
  height: '100%'; 
}

</style>

I know /s or [/s/S] or s would work but I dont how they will work

Regards

You can use pattern modifiers to match on multilines with PCRE regex : http://php.net/manual/en/reference.pcre.pattern.modifiers.php

m is the multiline modifier. s is the modifier to allow dot to match new lines too. So how about a pattern like this one:

'#<style>(.*?)</style>#ms'

I think you can also be interested in the imodifier since tags can be worded <style> or <STYLE> or other flavors <StYlE> wich are all valid.

use this:

 <style>([\s\S]*)<\/style>

DEMO

"." matches any single character except ,so '<style>(.*?)</style>' wouldn't work in multi line situation. while [\s\S]* will match any character including .