Regular line break

I am trying to replace everything between two tags, but I cannot build the correct expression.

This is what I did: /<tag>(.*|\n*)</tag>/

I want it to capture any characters, including line breaks.

This is an example of what I need to do:

 <tag>
       <div class="feed_title">Some Title</div>
       <div class="feed_content">Some text</div>
    </tag>

Can some of you tell me what I'm doing wrong?

Here is a link to RegExr and a complete example of what the content looks like: http://regexr.com?2t4n1

+3
source share
2 answers
'#.#m'

m stands for MULTILINE, it makes a dot capable of matching newlines = line breaks \ n

EDIT:

since he was corrected with sharp eyes and a good brain, he is obviously '#. + # s'

EDIT2:

,

$ch = '<tag>\s+<div class="feed_title">Some Title</div>\s+<div class="feed_content">Some text</div>\s+</tag>'

preg_match('#<tag>(.+?)</tag>#s',$ch,$match)

, s, :

preg_match('#<tag>((.|\s)+?)</tag>#',$ch,$match)

.

3:

, \s $ ch . \s RE, .

, , \t, <tag> ,

\t ; \s

+3

, ?

# The ... in this example is your text to match
preg_match("#<tag>(.*?)</tag>#s","...",$matches); 

XML PHP, .

+3

Source: https://habr.com/ru/post/1792941/


All Articles