[英]php regex to get middle of string
我將html頁面解析為純文本,以查找並獲取數字值。 在整個html混亂中,我需要找到一個像這樣的字符串:
C) Debiti33.197.431,90I - Di finanziamento
我需要數字33.197.431,90(其中每個HTML解析請求中的數字都會改變)。
有沒有正則表達式可以實現這一目標? 例如:
STARTS WITH 'C) Debiti' ENDS WITH 'I - Di finanziamento' GETS the middle string that can be whatever.
每當我嘗試時,都會得到空的結果……對正則表達式的了解不多。 你能幫我么? 非常感謝你。
您可以嘗試以下正則表達式,
^C\) Debiti\K.*?(?=I - Di finanziamento$)
PHP代碼是
<?php
$mystring = "C) Debiti33.197.431,90I - Di finanziamento";
$regex = '~^C\) Debiti\K.*?(?=I - Di finanziamento$)~';
if (preg_match($regex, $mystring, $m)) {
$yourmatch = $m[0];
echo $yourmatch;
}
?> //=> 33.197.431,90
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.