Linux 正则表达式分成几部分
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3677223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 23:27:29 来源:igfitidea点击:
Regex split into array of pieces
提问by Semas
I was wondering how could I split this string
我想知道我怎么能拆分这个字符串
{{MENU}}<li><a href="{{LINK}}" title="{{TITLE}}"><span>{{TITLE}}</span></a></li>{{/MENU}}
Into array of:
进入数组:
array(
"<li><a href=\"",
"{{LINK}}",
"\" title=\"",
"{{TITLE}}",
"\"><span>",
"{{TITLE}}",
"</span></a></li>"
)
It also should work with more different formats like:
它还应该适用于更多不同的格式,例如:
{{MENU}}<a href="{{LINK}}" title="{{TITLE}}">{{TITLE}}</a>{{/MENU}}
{{MENU}}<b><a href="{{LINK}}" title="{{TITLE}}">{{TITLE}}</a></b>{{/MENU}}
My problem is that I don't know how to write this complex regex yet.
我的问题是我还不知道如何编写这个复杂的正则表达式。
采纳答案by Colin Hebert
You can try with preg_split()
你可以试试 preg_split()
$yourArray = preg_split("/({{\w+}})/", $yourText, -1, PREG_SPLIT_DELIM_CAPTURE);
Resources :
资源 :
On the same topic :
在同一主题上: