Regular expression to get text between 2 string
Hi i need to get the content between 2 strings similar to tags like this:
[code]
some text and
new line
[/code]
I try with this regular expression but it works only without new line :
preg_match("/\[view\](.*)\[\/view\]/",$开发者_JAVA百科string, $results);
I need something that works also with newlines! and any characters i put between these 2 "tags" Any idea ?
Use the s
modifier in your call to do a multiline search:
preg_match("/\[view\](.*)\[\/view\]/s",$string, $results);
In the end, you should not be using regex to do complex parsing. It isn't up to the job. Find a markup language that suits your purpose and use an existing library to parse it.
精彩评论