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;
}
3
  • That sounds condescending... Answer: 0 or more of previous expression. In my defense, I've not used RegEx very much at all.. Commented Dec 13, 2009 at 13:22
  • Why the several =* then? Commented Dec 13, 2009 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. Commented Dec 14, 2009 at 2:55

1 Answer 1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.