Reputation: 474
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
Upvotes: 0
Views: 63
Reputation: 38
"." matches any single character except \n,so '<style>(.*?)</style>'
wouldn't work in multi line situation. while [\s\S]* will match any character including \n.
Upvotes: 0
Reputation: 2154
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 i
modifier since tags can be worded <style>
or <STYLE>
or other flavors <StYlE>
wich are all valid.
Upvotes: 1