Re: [PHP] trying to match the front and end...

2003-08-14 Thread John W. Holmes
Dan Joseph wrote:
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


Re: [PHP] trying to match the front and end...

2003-08-14 Thread CPT John W. Holmes
From: Dan Joseph [EMAIL PROTECTED]
 I've searched the high heavens for a method of doing this...  Here's what
 I'm doing... First, the code..

 $middlenum = preg_replace(/^.$this-start_num./, ,
 $this-ach_acct_num);
 $middlenum = preg_replace(/.$this-end_num.$/, , $middlenum);

 In a nutshell, what I want to do is chop off the front and the back.
 Example:

 I have: 1234567890
 I want: 456

 I have a start num and an end num.  start = 123, end = 7890.

 This is working fine as I have it above, however I'd like to combine it
into
 one regular express, instead of two.  Can someone give me an example of
 matching the beginning and end at the same time?

$new_number =
preg_replace('/^'.$this-start_num.'([0-9]+)'.$this-end_num.'$/','\\1',$old
_number);

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] trying to match the front and end...

2003-08-14 Thread Dan Joseph
Hi,

 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. :)

Ahh, you do have a very valid point there.

I tweaked your regex as stated in your follow up post, and mike's, they
both work now.  I'm gonna test a non-regex method.  Performance is a factor
in this.  I'll post my results in a day or two when I get it situated.

Thanks to you both!

-Dan Joseph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] trying to match the front and end...

2003-08-14 Thread Dan Joseph
Hi,

  In a nutshell, what I want to do is chop off the front and the back.
  Example:
 
  I have: 1234567890
  I want: 456
 
  I have a start num and an end num.  start = 123, end = 7890.
 
  This is working fine as I have it above, however I'd like to combine
  it into one regular express, instead of two.  Can someone give me an
  example of matching the beginning and end at the same time?

From Mike:

$middlenum =
 preg_replace(/^${this-start_num}(.*)${this-end_num}$/, '$1',
 $this-ach_acct_num);

From John:

 $new_number =
 preg_replace('/^'.$this-start_num.'([0-9]+)'.$this-end_num.'$/',
'\\1',$old
_number);

The one that Mike gave didn't seem to do anything, John's will work if it
can match the beginning and the end successfully.  I should probably explain
myself further.

Sometimes there won't be anything to replace at the front, and sometimes
nothing at the end.  So it'd still need to do the front and/or end wether or
not they both exist.

Is there a way to tweak these to do that?

-Dan Joseph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] trying to match the front and end...

2003-08-14 Thread John W. Holmes
Dan Joseph wrote:

From John:


$new_number =
preg_replace('/^'.$this-start_num.'([0-9]+)'.$this-end_num.'$/',
'\\1',$old
_number);
The one that Mike gave didn't seem to do anything, John's will work if it
can match the beginning and the end successfully.  I should probably explain
myself further.
Sometimes there won't be anything to replace at the front, and sometimes
nothing at the end.  So it'd still need to do the front and/or end wether or
not they both exist.
	Is there a way to tweak these to do that?
Should be:

$new_number =
preg_replace(
'/^('.$this-start_num.')?([0-9]+)('.$this-end_num.')?$/',
'\\2',
$old _number);
--
---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


Re: [PHP] trying to match the front and end...

2003-08-14 Thread John W. Holmes
Dan Joseph wrote:

Sometimes there won't be anything to replace at the front, and sometimes
nothing at the end.  So it'd still need to do the front and/or end wether or
not they both exist.
	Is there a way to tweak these to do that?
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?

--
---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


RE: [PHP] trying to match the front and end...

2003-08-10 Thread Ford, Mike [LSS]
On 08 August 2003 15:39, Dan Joseph wrote:

 I've searched the high heavens for a method of doing this...
 Here's what
 I'm doing... First, the code..
 
 $middlenum = preg_replace(/^.$this-start_num./, ,
 $this-ach_acct_num); $middlenum =
 preg_replace(/.$this-end_num.$/, , $middlenum); 
 
 In a nutshell, what I want to do is chop off the front and the back.
 Example: 
 
 I have: 1234567890
 I want: 456
 
 I have a start num and an end num.  start = 123, end = 7890.
 
 This is working fine as I have it above, however I'd like to combine
 it into one regular express, instead of two.  Can someone give me an
 example of matching the beginning and end at the same time?

   $middlenum = preg_replace(/^${this-start_num}(.*)${this-end_num}$/, '$1', 
$this-ach_acct_num);

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] trying to match the front and end...

2003-08-09 Thread Dan Joseph
Hi,

 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?

-Dan Joseph


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] trying to match the front and end...

2003-08-08 Thread Ford, Mike [LSS]
On 08 August 2003 17:39, Dan Joseph wrote:

 Hi,
 
   In a nutshell, what I want to do is chop off the front and the
   back. Example: 
   
   I have: 1234567890
   I want: 456
   
   I have a start num and an end num.  start = 123, end = 7890.
   
   This is working fine as I have it above, however I'd like to
   combine it into one regular express, instead of two.  Can someone
   give me an example of matching the beginning and end at the same
   time? 
 
 From Mike:
 
 $middlenum =
  preg_replace(/^${this-start_num}(.*)${this-end_num}$/, '$1',
  $this-ach_acct_num);
 
 From John:
 
  $new_number =
  preg_replace('/^'.$this-start_num.'([0-9]+)'.$this-end_num.'$/',
 '\\1',$old
 _number);
 
   The one that Mike gave didn't seem to do anything,

Oops!! Forgot to escape the final $ in the pattern -- should have read:

preg_replace(/^${this-start_num}(.*)${this-end_num}\$/, '$1',
$this-ach_acct_num);

 John's will work if it
 can match the beginning and the end successfully.  I should probably
 explain myself further.
 
   Sometimes there won't be anything to replace at the front, and
 sometimes nothing at the end.  So it'd still need to do the front
 and/or end wether or not they both exist.
 
   Is there a way to tweak these to do that?

If $this-start_num or $this-end_num contains the empty string (or even
NULL or FALSE), nothing will be interpolated into the string for those
values, so the above (corrected) pattern will still work.  If
nothing-to-replace is signalled by something else, you may have a bit more
work to do...

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php