Ask a Question related to PHP Development, Design and Development.
-
Mike Ford #1
RE: [PHP] trying to match the front and end...
On 08 August 2003 15:39, Dan Joseph wrote:
$middlenum = preg_replace("/^${this->start_num}(.*)${this->end_num}$/", '$1', $this->ach_acct_num);> 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?
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]m.ford@lmu.ac.uk[/email]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Mike Ford Guest
-
Front End SQL Statement
Does anyone know a SQL statement that can run a macro or a module within ACCESS? -or- A CF Command/Tag that can run a macro or module within... -
Anyway to run a DB Macro from a CF web front end?
Good morning, I was wondering if anyone knew of a way i could click a button on a CF web page which would run a query in our ACCESS DB? anyone... -
Enlarge the front of a car?
I have a shot of a car that is almost coming directly at the viewer. You can actually see the side of the car, but very slightly. I would like to be... -
Minus Front
I hope this isn't an overly stupid question, but how do I "minus front" in AI 11.0? In 9.0 and 10.0, there's a command in the Pathfinder palette... -
IE5 or Front Panel ?????
Gang, We have a machine running Solaris 2.6 on which I installed Internet Explorer 5. I install it as root and it runs fine. It starts by... -
Cpt John W. Holmes #2
Re: [PHP] trying to match the front and end...
From: "Dan Joseph" <djoseph@duhq.us>
into> 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$new_number => one regular express, instead of two. Can someone give me an example of
> matching the beginning and end at the same time?
preg_replace('/^'.$this->start_num.'([0-9]+)'.$this->end_num.'$/','\\1',$old
_number);
---John Holmes...
Cpt John W. Holmes Guest
-
Dan Joseph #3
RE: [PHP] trying to match the front and end...
Hi,
From Mike:> > 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 John:> $middlenum =
> preg_replace("/^${this->start_num}(.*)${this->end_num}$/", '$1',
> $this->ach_acct_num);
'\\1',$old> $new_number =
> preg_replace('/^'.$this->start_num.'([0-9]+)'.$this->end_num.'$/',
_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
Dan Joseph Guest
-
John W. Holmes #4
Re: [PHP] trying to match the front and end...
Dan Joseph wrote:
Should be:>>>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?
$new_number =
preg_replace(
'/^('.$this->start_num.')?([0-9]+)('.$this->end_num.')?$/',
'\\2',
$old _number);
--
---John Holmes...
Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]
PHP|Architect: A magazine for PHP Professionals – [url]www.phparch.com[/url]
John W. Holmes Guest
-
Mike Ford #5
RE: [PHP] trying to match the front and end...
On 08 August 2003 17:39, Dan Joseph wrote:
Oops!! Forgot to escape the final $ in the pattern -- should have read:> 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:
>> '\\1',$old> > $new_number =
> > preg_replace('/^'.$this->start_num.'([0-9]+)'.$this->end_num.'$/',
> _number);
>
> The one that Mike gave didn't seem to do anything,
preg_replace("/^${this->start_num}(.*)${this->end_num}\$/", '$1',
$this->ach_acct_num);
If $this->start_num or $this->end_num contains the empty string (or even> 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?
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]m.ford@lmu.ac.uk[/email]
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
Mike Ford Guest
-
John W. Holmes #6
Re: [PHP] trying to match the front and end...
Dan Joseph wrote:
$start_length = strlen($this->start_num);>>>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?
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: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]
PHP|Architect: A magazine for PHP Professionals – [url]www.phparch.com[/url]
John W. Holmes Guest
-
Dan Joseph #7
RE: [PHP] trying to match the front and end...
Hi,
Ahh, you do have a very valid point there.> 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. :)
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
Dan Joseph Guest



Reply With Quote

