Php 正则表达式的语法

Php 正则表达式的语法,php,regex,Php,Regex,我目前正在开发一个php程序,但我有一个问题: 我有一个字符串,想提取其中的一部分。所以我尝试使用正则表达式,但显然不起作用。 守则: 和绳子的一部分 <th scope="row" class="direction-name"> Direction BLABLA1 - BLABLA2 </th> <td class="departure-time"> <span>15h30</span> </td>

我目前正在开发一个php程序,但我有一个问题: 我有一个字符串,想提取其中的一部分。所以我尝试使用正则表达式,但显然不起作用。 守则:


和绳子的一部分

    <th scope="row" class="direction-name"> Direction BLABLA1 - BLABLA2 </th>
<td class="departure-time">
    <span>15h30</span>
</td>
方向BLABLA1-bla2
15h30
我只想保留“废话”。 那么我的错误在哪里呢? 谢谢你的阅读
祝您愉快

您可以使用此
regex


/
\s*方向\s*(.*?\s*-
/

以下是您问题的一行答案

<?php
$direction=preg_match('#direction-name">\s*Direction\s*(.+)?\s*-\s.*?<*#i',
$chaine_de_caractere,$direction)?$direction[1]:'unknown';
echo $direction;

您想要得到什么?您也可以使用-->\>\s?方向(.*)\-下面是一个示例-->