我正在运行RST到php的转换,并使用preg_match。
这是我试图识别的RST:
An example of the **Horizon Mapping** dialog box is shown below. A
summary of the main features is given below.
.. figure:: horizon_mapping_dialog_horizons_tab.png
**Horizon Mapping** dialog box, *Horizons* tab
Some of the input values to the **Horizon Mapping** job can be changed
during a Workflow using the internal programming language, IPL. For
details, refer to the *IPL User Guide*.
,我使用这个正则表达式:
$match = preg_match("/.. figure:: (.*?)('n{2}[ ]{3}.*'n)/s", $text, &$result);
返回false。下面是一个表达式在正则表达式上工作的链接http://regex101.com/r/oB3fW7。
您确定换行符是'n
,如果有疑问,请使用'R
:
$match = preg_match("/.. figure:: (.*?)('R{2}[ ]{3}.*'R)/s", $text, &$result);
'R
分别代表'n
、'r
和'r'n
我的直觉是围绕s
标志以及通过引用传递的$result
变量进行一些故障排除。要达到相同的效果,而不受点和返回变量的干扰,请尝试以下regex:
..[ ]figure::[ ]([^'r'n]*)(?:'n|'r'n){2}[ ]{3}[^'r'n]*'R
在代码中,请完全像这样尝试:
$regex = "~..[ ]figure::[ ]([^'r'n]*)(?:'n|'r'n){2}[ ]{3}[^'r'n]*'R~";
if(preg_match($regex,$text,$m)) echo "Success! </br>";
最后:
如果这不起作用,您可能有一个奇怪的Unicode换行,php无法捕获。要进行调试,对于字符串中的每个字符,遍历字符串中的所有字符
- Iterate:
foreach(str_split($text) as $c) {
- 打印字符:
echo $c . " value = "
- 打印此函数的值:
. _uniord($c) . "<br />"; }