0

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;
}
Brad
  • 2,237
  • 5
  • 41
  • 69
  • That sounds condescending... Answer: 0 or more of previous expression. In my defense, I've not used RegEx very much at all.. – Brad Dec 13 '09 at 13:22
  • Why the several =* then? – Alix Axel Dec 13 '09 at 13:31
  • Because I don't really know what I'm doing with RegEx... It's still a little confusing to me. I'm at least "TRYING" to figure it out, VS ask someone else to do all the work for me. I could have said here's this what's the regex for this. – Brad Dec 14 '09 at 02:55

1 Answers1

5

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
  • 507,862
  • 82
  • 626
  • 550