开发者

Regular expression to get text between 2 string

开发者 https://www.devze.com 2023-02-03 12:57 出处:网络
Hi i need to get the content between 2 strings similar to tags like this: [code] some text and new line

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消