【发布时间】:2010-11-24 00:45:06
【问题描述】:
我正在使用 PHP 制作脚本语言解释器。我有这个脚本语言的代码:
write {Hello, World!} in either the color {blue} or {red} or {#00AA00} and in either the font {Arial Black} or {Monaco} where both the color and the font are determined randomly
(是的,很难相信,但这就是语法)
我必须使用哪个正则表达式来分割它(用空格分割),但前提是不在大括号内。所以我想把上面的代码变成这个数组:
- 写
- 你好,世界!
- 在
- 要么
- 颜色
- 蓝色
- 或
- 红色
- 或
- #00AA00
- 和
- 在
- 要么
- 字体
- 宋体黑
- 或
- 摩纳哥
- 在哪里
- 两者都有
- 颜色
- 和
- 字体
- 是
- 确定
- 随机
(大括号内的字符串以粗体显示) 花括号内的字符串每个必须是一个元素。所以 {Hello, World!} 不能是: 1. 你好, 2.世界!
我该怎么做?
提前致谢。
【问题讨论】:
标签: php regex programming-languages preg-split