views:

44

answers:

1

This is what I've got for for my RegEx, I was wondering if this is the best way.

I want to be able to find something similar regardless of the spacing between Identifiers and not be case sensitive. And if possible, not worry about order..

Example:

[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"    ]

Here's my existing Code:

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;
}
+5  A: 

I'd use \s* to match indefinite amounts of whitespace; this allows you to include all forms of whitespace, not just regular spaces (and thus you can match tabs, etc).

'@\[Foreclosure\s*=\s*"(.*?)"\s*url\s*=\s*"(.*?)"\s*title="(.*?)"\s*\]@si'
Amber
Works Perfectly, Thank you Dav.
Brad
accept his answer then!
Jan Hančič