Regular Expressions

This is a discussion on Regular Expressions within the PHP Language forums, part of the PHP Programming Forums category; Hi all Hopefully a nice easy one :o) I've got a table with a list of 'installers'. I have ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-24-2005
Andy Jacobs
 
Posts: n/a
Default Regular Expressions

Hi all

Hopefully a nice easy one :o)

I've got a table with a list of 'installers'. I have a form for
visitors to find an installer in their area searchning on post code.

Let's say we have installers in:

RG (Reading)
G (Glasgow)

The page tells the vistor to type in the first letter(s) of their post
code. So, if a visitor types in their postcode as RG23 1TQ, it works.
If they type in G23 1TQ then it doesn't. If they type in just G - as
instructed - then it works.

I've just chopped off all but the first 2 digits of whatever they type
in (RG or G2). What I would like to do is (In pigeon PHP):

If characters one and two are letters, use this for the search.

If character one is a letter and character two is a number then just
chop the first character off and use it for the search.

elseif display error.

What I can't get my head round is the logic and regular expressions
behind this.

Could someone throw me a lifeline please.

Cheers

Andy
Reply With Quote
  #2 (permalink)  
Old 01-24-2005
Mick White
 
Posts: n/a
Default Re: Regular Expressions

Andy Jacobs wrote:

> Hi all
>
> Hopefully a nice easy one :o)
>
> I've got a table with a list of 'installers'. I have a form for
> visitors to find an installer in their area searchning on post code.
>
> Let's say we have installers in:
>
> RG (Reading)
> G (Glasgow)
>
> The page tells the vistor to type in the first letter(s) of their post
> code. So, if a visitor types in their postcode as RG23 1TQ, it works.
> If they type in G23 1TQ then it doesn't. If they type in just G - as
> instructed - then it works.
>
> I've just chopped off all but the first 2 digits of whatever they type
> in (RG or G2). What I would like to do is (In pigeon PHP):
>
> If characters one and two are letters, use this for the search.
>
> If character one is a letter and character two is a number then just
> chop the first character off and use it for the search.
>
> elseif display error.
>
> What I can't get my head round is the logic and regular expressions
> behind this.


Grab the first 2 characters (if the entry is 2 or more characters)

replace digit with "" (Nothing)

Mick

Reply With Quote
  #3 (permalink)  
Old 01-24-2005
Michael Fesser
 
Posts: n/a
Default Re: Regular Expressions

.oO(Andy Jacobs)

>I've just chopped off all but the first 2 digits of whatever they type
>in (RG or G2). What I would like to do is (In pigeon PHP):
>
>If characters one and two are letters, use this for the search.
>
>If character one is a letter and character two is a number then just
>chop the first character off and use it for the search.
>
>elseif display error.


if (preg_match('#^[a-z]{1,2}#i', $yourString, $result)) {
// use $result[0] for search
} else {
// error handling
}

Micha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:26 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0