0

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

2
  • 4
    Use this regex: '#<style>(.*?)</style>#s' Commented Jun 23, 2015 at 11:21
  • 1
    you're answer was the first answer and correct one for me , but could not accept answer as it is a comment. Anyways , thanks :) Commented Jun 24, 2015 at 5:26

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

use this:

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

DEMO

Comments

0

"." 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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.