Question: Where is this number coming from? Couldn't you just use a substr() based upon it's length and not deal with a regular expression?
Its a bank account number coming from a database. We're reformatting it for ACH processing. The number could be:
23408234980423
with a rule of remove 12453 from beginning, and remove 0423 from the end, that would leave us with 2340823498. The rule could also read to remove 234 from the beginning, and 43985 from the end, leaving us 08234980423.
The length of the number is also dynamic.
I guess I just found it easier to go over it with a couple regular expressions, then got to thinking maybe I could combine it into one. What suggestion would you have?
$start_length = strlen($this->start_num); if(substr($number,0,$start_length) == $this->start_num) { $number = substr($number,$start_length); }
$end_length = 0 - strlen($this->end_num); if(substr($number,$end_length) == $this->end_num) { $number = substr($number,0,$end_length); }
Not tested, mind you. I know what you're saying, too. How is _all_ of that code better(worse?) than one simple regex? Benchmark it and see. You'll be surprised how a lot more code with simple string functions will be considerably faster than a complex regular expression. Your results may vary, though. :)
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
PHP|Architect: A magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php