Php 休闲模式的正则表达式

Php 休闲模式的正则表达式,php,regex,Php,Regex,我想在('some number或characters')之前添加-,并在下一个模式暂停时的末尾添加,我将给出示例: $text = "(1) Some text here.(2) More text here (B) Again text; (iii) Final: "; 所需的输出将是: $desiredFormatedText = "-(1) Some text here.<br>-(2) More text here <br>-(B) Again text; &

我想在('some number或characters')之前添加
-
,并在下一个模式暂停时的末尾添加

,我将给出示例:

$text = "(1) Some text here.(2) More text here (B) Again text; (iii) Final: ";
所需的输出将是:

$desiredFormatedText = "-(1) Some text here.<br>-(2) More text here <br>-(B) Again text; <br>-(iii) Final: ";
$desiredFormattedText=“-(1)此处有一些文本。
-(2)此处有更多文本
-(B)再次文本;
-(iii)最终文本:”;
使用php,我尝试了以下方法:

$desiredFormatedText = preg_replace('regex...', '$1-<br>', $text);
$desiredFormattedText=preg_replace('regex…','$1-
',$text);
但是我想不出正确的正则表达式语法?

在开头匹配
(…)
,然后在结尾的前瞻中再次匹配它。然后将
-

放在替换中匹配的字符串周围

preg_replace('/\(\w+\).*?(?=\(\w+\))/', '-$0<br>', $text);
preg\u replace('/\(\w+\).*(?=\(\w+\)/','-$0
,$text);

我只想提到的是学习和理解正则表达式模式的一个很好的资源。它没有在末尾添加一个“-:
(iii)Final:should:
(iii)Final:逻辑是什么?比赛前有
-
,比赛后有

。最后一个句子前面只有
-
,后面没有

。因为这个句子最后会输出这样的内容:-(1)这里有一些文本。(新行)-(2)这里有更多这样的文本(新行),直到(iii)最后,前面不会有“-”。当它发现(模式)一个句子在另一个句子的下面,每个句子前面都有一个“-”时,它应该输出每个匹配的句子,最后一个句子前面不会有“-”。