3
在PHP中的問題,我用下面的正則表達式這裏http://pastebin.com/PfjEgQpd匹配的文本:與ungreedy比賽
preg_match('#(.*(?s))(particella |particelle |p\.|part\.|p |part |mappale |mapp\.|mapp |n\.|\*) *(\d+[\d /\p{Pd}]*)($|.{0,20}(?s)(graffati|particella |particelle |p\.|.*part\.|p |part |mappale |mapp\.|mapp |n\.|subalterno |subalterni |sub\.|s\.|sub |s |\bcat\b|\bcategoria\b|\brendita\b|\bvani\b|\bconsistenza\b|\bR\.C\.\b))#i', $txt, $matches, PREG_OFFSET_CAPTURE, $offset)
與$offset = 944
,我得到以下輸出$matches
。
我預計匹配1184
但它相匹配的4
代替。 我也試過(?sU)
也沒有運氣。
$matches = array(6) {
[0]=>
array(2) {
[0]=>
string(59) "* 1184 sub.702, vioolo San Vincenzo n.4, piano T, Categoria"
[1]=>
int(1226)
}
[1]=>
array(2) {
[0]=>
string(36) "* 1184 sub.702, vioolo San Vincenzo "
[1]=>
int(1226)
}
[2]=>
array(2) {
[0]=>
string(2) "n."
[1]=>
int(1262)
}
[3]=>
array(2) {
[0]=>
string(1) "4"
[1]=>
int(1264)
}
[4]=>
array(2) {
[0]=>
string(20) ", piano T, Categoria"
[1]=>
int(1265)
}
[5]=>
array(2) {
[0]=>
string(9) "Categoria"
[1]=>
int(1276)
}
}
$offset = int(944)
偏移量是多少?順便說一句,你的模式非常脆弱,可能會造成災難性的回溯。爲了解決這個問題,我需要知道你到底想用什麼來解壓。 –
我這裏http://siba.thenetworksolution.it/allegati/H3018500D7FDDE9ACA05671F49F4F3746A69DAF96.1329514.pdf.txt同樣的問題 同樣的正則表達式用而不是‘454’偏移= 1155場比賽'57/1998' 。在這種情況下,懶惰子模式將無濟於事。我試圖提取地籍數據「foglio 1,particella 454,sub.4 e sub.5。」。這是應該匹配「particella」的正則表達式:454.我提供的偏移量是「foglio 1」的偏移量(先前在我的代碼中與另一個正則表達式匹配)。 –
我檢查過了,看起來你的正則表達式也匹配['57/1998'](https://ideone.com/rvLGFE)。 –