0

这就是我为我的 RegEx 所做的,我想知道这是否是最好的方法。

无论标识符之间的间距如何,我都希望能够找到类似的东西,并且不区分大小写。如果可能的话,不要担心订单..

例子:

[Foreclosure ="Remax" URL="http://www.remax.com" Title = "4 Bedroom 2 Bath Condo"]
[Foreclosure ="Remax"URL="http://www.remax.com"Title="4 Bedroom 2 Bath Condo"]
[Foreclosure  =   "Remax"    URL="http://www.remax.com"     Title = "4 Bedroom 2 Bath Condo"    ]

这是我现有的代码:

function ForeclosureCode_filter( $buffer )
{
    //There might be a better way to do the regex...  But this seems to work...
    $buffer = preg_replace_callback( '@\[Forclosure *=*"(.*?)" *url *=*"(.*?)" *title="(.*?)" *\]@si',
        "ForeclosureCode_replace", $buffer );
    return $buffer;
}
4

1 回答 1

5

我会\s*用来匹配无限量的空格;这允许您包含所有形式的空格,而不仅仅是常规空格(因此您可以匹配制表符等)。

'@\[Foreclosure\s*=\s*"(.*?)"\s*url\s*=\s*"(.*?)"\s*title="(.*?)"\s*\]@si'
于 2009-12-13T13:16:31.180 回答